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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to create new column in sql?

Author  Topic 

tamancha.1
Starting Member

37 Posts

Posted - 2010-09-28 : 13:18:04
var1 var2 new variable

tov2009 lead01 Free Trial Buttons
tov2009 pgview Page Views
oab2009 pgview1 Page Views
tov2009 visits All Unique Visits
oab2009 visits1 All Unique Visits

In the above table I want to create a "new Variable" in SQL based on combination of var1 and var2?

For example if var1=tov2009 and var2=lead01 then new variable=Free Trial Buttons

Any idea how to do it?Thanks.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-09-28 : 13:29:03
select other_columns, case when var1=tov2009 and var2=lead01 then 'Free Trial Buttons
' else NULL end as new_col from your_table

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -