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
 Does a value exist?

Author  Topic 

GavinD1977
Yak Posting Veteran

83 Posts

Posted - 2007-06-04 : 11:48:35
Hi all.

Can anyone tell me how to search a column for a value........for example 'STANDARD' and if it doesnt exist, enter it?

thanks all.

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-06-04 : 11:50:49
[code]IF not Exists(select * from Table where SomeCol = 'STANDARD')
Insert into Table(SomeCol)
values('STANDARD')
GO[/code]


or

[code]Insert into Table(SomeCol)
Select 'STANDARD' where not exists(select * from Table where SomeCol = 'STANDARD')[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

GavinD1977
Yak Posting Veteran

83 Posts

Posted - 2007-06-04 : 11:54:22
brilliant............thanks Harsh.
Go to Top of Page
   

- Advertisement -