Use of Date time

October 26, 2007 at 12:43 pm | In SQL Server | Leave a Comment

To display date in format : dd/mm/yyyy

convert(varchar(12),[field name],103)

To get records between two dates use following syntax in where condition.
Note : 1) Assuming that field type is varchar in database table.
2) From date & to date variables are in date format.

Convert(datetime,Convert(varchar(12),[field name])) between Convert(datetime,[from date variable] ) and Convert(datetime,[to date variable])

Using Cursor – Basic syntax

October 26, 2007 at 12:29 pm | In SQL Server | Leave a Comment

Using Cursor – Basic syntax

DECLARE [cursor name] CURSOR
FOR

[SELECT query ]

OPEN [cursor name]

[DECLARE variables]

FETCH NEXT FROM [cursor name] INTO [variable list]

WHILE(@@FETCH_STATUS -1)
BEGIN
IF(@@FETCH_STATUS -2)
BEGIN
[Insert/Update statements]
END
FETCH NEXT FROM [cursor name] TO[variable list]
END
CLOSE [cursor name]
DEALLOCATE [cursor name]

Blog at WordPress.com. | Theme: Pool by Borja Fernandez.
Entries and comments feeds.