Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Add a 1 to every line

Author  Topic 

Amber_Deslaurier
Starting Member

40 Posts

Posted - 2010-05-29 : 14:06:51
Hi!

I need to add 1 to every line where the field next to it is not null <> Null.... I am assuming I have to use a case?

Thanks

Amber

Sachin.Nand

2937 Posts

Posted - 2010-05-29 : 16:45:46
Yes.
Here is a test query.

declare @tbl as table(num int,value int)
insert into @tbl
select 1,null union all
select 1,2 union all
select 5,NULL union all
select 5,5

select num,value,case value when nullif(value,null) then num+1 else num end as newvalue from @tbl


PBUH
Go to Top of Page
   

- Advertisement -