Click to See Complete Forum and Search --> : put Select count statement into a variable -- help!!
Bebe
May 24th, 2000, 05:00 AM
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?
Gen-X
May 24th, 2000, 06:35 AM
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 :
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?
curlywink
May 24th, 2000, 06:37 AM
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...
Bebe
May 24th, 2000, 08:12 AM
Thank you Gen x; that was exactly it.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.