Hi,
I have table like below in Sqlserver.
QID UAnswer1 UAnswer2
1 Null 2
2 1 Null
3 Null 2
I have to insert the values into table as For QID"4" user answer is 1 then It should save as for 4 Uanswer1 as "1" and Uanswer2 should be null. Like that i have to insert data into table. How can i achieve this?
Any one please help me........
Thanks & Regards,
Nagaraju.
Loading
Priya LingePosted Aug 10, 2011, 6:07 AM
Here declare the values as you want
declare @noofrows int
declare @cnt int
set @noofrows=10
set @cnt=1
while @cnt< @noofrows
begin
if (@cnt%2)= 0
begin
insert into Production..USERAnswer values(@cnt,1,null)
end
else
begin
insert into Production..USERAnswer values(@cnt,null,2)
end
set @cnt=@cnt+1
end
OutPut :
UID ANS1 ANS2
1 NULL 2
2 1 NULL
3 NULL 2
4 1 NULL
5 NULL 2
6 1 NULL
7 NULL 2
8 1 NULL
9 NULL 2
Thanks.
Jiteendra SampathiraoPosted Aug 10, 2011, 5:55 AM
first use the property default null to UAnswer1, UAnswer2..
then write like
insert into table_name values (4, 1);
other wise write this query
insert into table_name (QID, UAnswer1, UAnswer2) values (4, 1, null);
hope it help you.........