|
-
May 24th, 2000, 05:00 AM
#1
Thread Starter
Addicted Member
How do I put a select statement into a variable? Do I declare it and with what?
SELECT COUNT (*)as 'Your a Lammo' from dbo.vw_Lammo
Where vendor_err='x' and created_dt>@FromDate
How would I put this into a variable? or the count of this into a variable in SQL?
-
May 24th, 2000, 06:35 AM
#2
Hyperactive Member
I am not really sure what you are asking here.
I get the "impression" you want to know how to set a variable to a record count in TRANSACT-SQL for use in a STORED PROCEDURE.
If that *IS* what you are asking you do it like this :
Code:
delcare @@totalrecords integer
SELECT @@totalrecords = count(*) FROM table WHERE x = 10
if @@totalrecords > 0
begin
<Do whatever you want>
end
Note that you MUST have 2 ats (@) before the declaration as Transact-SQL uses single @ to describe common variables and @@ to describe variables set from SELECT statements.
If this is NOT what you were meaning then you are going to have to explain yourself again. Are you using VB? Is it in a record set? Where are you putting it? What is it doing?
-
May 24th, 2000, 06:37 AM
#3
Addicted Member
Hi there,
'wanna try this ...
Dim rst as Recordset
Dim YourVariable as Integer
Set rst = dbAnything.OpenRecordSet("SELECT COUNT (*)as Lammo from dbo.vw_Lammo Where vendor_err='x' and created_dt>@FromDate ")
YourVariable = rst!Lammo
Hope this can help ...
dbAnything = 'ur Database object...
-
May 24th, 2000, 08:12 AM
#4
Thread Starter
Addicted Member
Thank you Gen x; that was exactly it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|