Monday, 5 November 2012

Cursors in sql server?


--Tsql Programming
DECLARE @MONTH int
SET @MONTH=DATEPART(MM,GETDATE())
if @MONTH=1
 print 'jan'
 if @MONTH=2
 print 'feb'
 if @MONTH=3
 print 'march'
 else
 print 'year almost in ending'

--CASE STATEMENT
--simple case
DECLARE @CASEEXAMPLE int
SET @CASEEXAMPLE=MONTH(GETDATE())
select CASE @CASEEXAMPLE
when 1 then 'jan'
when 2 then 'feb'
when 10 then 'march'
when 11 then 'november'
END
--Search case
DECLARE @SECONDCASE DATETIME
SET @SECONDCASE=GETDATE()
select case
when @SECONDCASE>'10/05/2012' then 'year is in second quareter'
end
select DATEPART(ww,getdate())
-- while loop
DECLARE @X int
SET @X=0
WHILE @X<10
BEGIN
SET @X=@X+1
print 'x is incrementing'
END
--

 DECLARE @y int
  SET @y=0
  while @y<10
  begin
  set @y=@y+1
  if @y>6 continue
  print @y

  END

No comments:

Post a Comment