-
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?
-
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?
-
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...
-
Thank you Gen x; that was exactly it.