SQL inserting value of a specific column under multple case
Posted
by
Lo Wai Lun
on Stack Overflow
See other posts from Stack Overflow
or by Lo Wai Lun
Published on 2012-10-15T03:33:36Z
Indexed on
2012/10/15
3:36 UTC
Read the original article
Hit count: 255
sql
|sql-server
Suppose I have got a table which I have to insert the description of the contract under different keys of contract.
But when executing, there is a n error near then
Is there any limitation of using syntax set ?
The below is my SQL
declare @i int, @j v nvarchar(MAX)
set @i = 1
while (@i<=8)
begin
set @j = case when @i = 1 then 'CR' when @i = 2 then 'Facebook' else 'N/A' end
INSERT INTO CostNature (CNKey, CNNDescription) VALUES (@i , @j );
set @i = @i + 1
end
© Stack Overflow or respective owner