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
 Combining data from two columns

Author  Topic 

nasir_mmalik
Starting Member

2 Posts

Posted - 2009-03-05 : 12:15:15
I am very new to SQL Development, so I want to apologize in advance if the question is weak. Here is what I am looking to do....I have a table with data in it but it has one empty column (LastColumn). What I am trying to achieve is see if data in first column (column1) is a positive or a negative. If its positive then add some string (somestring) to join it with data in another column(Column2) and insert the cojoined data in LastColumn.
Column1 is int
Column2 is nvarchar
LastColumn is nvarchar

Eg... if data in column1 = -2 and data in column2 = ABC then i should ne able to insert -2ABC in LastColumn.

What would be the best approach to do this...stored procedure??

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-05 : 12:24:35
do you mean this?


UPDATE Table
SET LastColumn=CASE WHEN column1 <0 THEN CAST(column1 AS varchar(10)) + column2
ELSE 'somestring' + column2
END
Go to Top of Page

nasir_mmalik
Starting Member

2 Posts

Posted - 2009-03-05 : 13:35:20
No I meant soemthing like


UPDATE Table
SET LastColumn=CASE WHEN column1 <0 THEN CAST(column1 AS varchar(10)) + column2 ('someoptherstring' + column2)
ELSE 'somestring' + column2
END
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-03-07 : 13:18:16
then wat was purpose of this?

Eg... if data in column1 = -2 and data in column2 = ABC then i should ne able to insert -2ABC in LastColumn.
Go to Top of Page
   

- Advertisement -