Sunday, February 15, 2009

Good T-SQL tutorial

For those of you who would like to know T-SQL

http://www.databasejournal.com/features/mssql/article.php/3087431/T-SQL-Programming-Part-1---Defining-Variables-and-IFELSE-logic.htm

An example T-SQL script


declare @jobId int

declare JobList cursor for select id from tsktask where fkparenttaskid is not null


OPEN JobList
FETCH NEXT FROM JobList INTO @jobId

WHILE @@FETCH_STATUS = 0
BEGIN

declare @parentTaskId int
SET @parentTaskId = (select fkParentTaskId from TskTask where id = @jobId)

declare @runNo varchar(25)
SET @runNo = (select identifier from tsktask where id = @parentTaskId)

update tsktask
set identifier = @runNo
where id = @jobId


FETCH NEXT FROM JobList INTO @jobId
END

CLOSE JobList
DEALLOCATE JobList

No comments: