April 8, 2010 at 5:46 am
Hi,
i want to use the if to check i the column not have those to rows in it.how can i do that?
THX
create table test (column1 nvarchar (10))
go
insert into test values ('test')
go
insert into test values ('test1')
go
if not exists (select column1 from test where column1 = 'test' and column1 = 'test1')
begin
print 'do sonething'
end
April 8, 2010 at 7:20 am
Change your and to an OR
if not exists (select column1 from #test where column1 = 'test' OR column1 = 'test1')
But what are you doing ... inserting new rows, updating existing rows, deleteing rows?
How many different (test / test1) values will you be testing to determine if the value currently exists?
Please post more information - there are most likely better and faster ways to accomplish what you want to do.
create table #test (column1 nvarchar (10))
insert into #test values ('test')
insert into #test values ('test1')
if not exists (select column1 from #test where column1 = 'test' OR column1 = 'test1')
print 'do sonething'
ELSE
print 'got them'
April 8, 2010 at 10:36 am
the OR is if one of them not exists then it will execute the if.
i want to check if both rows not exists then do the if.
i need to check for 2 rows in that column if they not exists do something.
the rows will always be the same "mem","cpu".
THX
April 8, 2010 at 12:19 pm
i want to check if both rows not exists then do the if.
i need to check for 2 rows in that column if they not exists do something.
the rows will always be the same "mem","cpu".
Then you will need to do a separate test for each case.
If ((Not Exists ( ... Column1 = 'mem')) And (Not Exists ( ... Column1 = 'cpu')))
Begin;
-- Do Something;
End;
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply