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)
 Record Exists

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-03-16 : 11:30:20
Hello,

I have the following:
SELECT * FROM dbo.Blogs WHERE BlogId = @BlogId

I need to check if such a record exist but not now. Later in my code.
I suppose I should create a BIT variable.

Could someone tell me how to do this?

Thanks,
Miguel

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-03-16 : 11:33:02
you can use exists

where exists (SELECT * FROM dbo.Blogs WHERE BlogId = @BlogId)



KH

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-16 : 11:48:48
quote:
Originally posted by khtan

you can use exists

where exists (SELECT * FROM dbo.Blogs WHERE BlogId = @BlogId)



KH





That would be

IF EXISTS



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2007-03-16 : 11:51:09
Yes I know that.

But that's not the question.
In VB.NET would be something like this:

Dim aBIGGERb As Boolean = (a>b)
Dim cBIGGERb As Boolean = (c>b)
...

Then later on my code I would do:

If aBIGGERb AND cBIGGERb Then Response.Write("c is bigger than a")

You see?

I need to create various variables in SQL which will hold information as if certain records exist. Then later on my code I will test various combinations.

Any idea?

Thanks,
Miguel
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-03-16 : 11:54:28
if exists (SELECT * FROM dbo.Blogs WHERE BlogId = @BlogId)
set @param1 = 1
else
set @param1 = 0


if exists (SELECT * FROM dbo.Blogs WHERE BlogId = @BlogId2)
set @param2 = 1
else
set @param2 = 0

select *, case when @param1 > @param2 then 'ewrnrew' else 'wereljn' end as status
from table


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2007-03-16 : 13:11:43
It's a vb question...which in and of itself is the wrong forum, however, the way it's presented is incorrect...the process is flawed

Let us know what you need to do instead of trying to force a tech solution to a process that needs to be altered



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -