我有一个SQL Server表,其中包含2列Code和CodeDesc。我想使用T-SQL遍历行并打印CodeDesc的每个字符。怎么做?
如果您真的想遍历各行,则需要使用光标。
光标
DECLARE @temp YOURTYPE DECLARE c CURSOR FOR SELECT CodeDesc FROM authors OPEN c FETCH NEXT FROM c INTO @temp WHILE @@FETCH_STATUS = 0 BEGIN -do something with temp FETCH NEXT INTO @temp END CLOSE c DEALLOCATE c