Wednesday, September 23, 2009

Checking weather a string is within a string

The following query checks weather a string in within another string or not.


DECLARE @part AS VARCHAR(50)
DECLARE @wholeword AS VARCHAR(50)
set @part='to'         --The string you want to search
set @wholeword='I need to find'--The string you want to check in
if charindex(@part, @wholeword) > 0
print 'is inside'
else
print 'is not inside'

Simple n Cool ha...!

Tuesday, September 22, 2009

SQL PIVOT – resulting rows in to columns in sql

In some cases you’ll have to generate cross-tabulation reports to summarize data. Most popular method in these kinds of situations is using a “Select Case” clause. But it’ll be more easier and effective if you use the PIVOT.
PIVOT provides syntax that is simpler and more readable than what may otherwise be specified in a complex series of SELECT...CASE statements.


A common scenario where PIVOT can be useful is when you want to generate cross-tabulation reports to summarize data.

See how it is done