Results 1 to 4 of 4

Thread: put SQL statement into a variable -- Please answer!!!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    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?

  2. #2
    Guest

    Question Note sure if this answers your question but....

    Private sSQL as String
    Private rData as Recordset

    sSQL = "SELECT......whatever"


    Set rData = db.OpenRecordset(sSQL)


    Hope it helps

  3. #3
    New Member
    Join Date
    May 2000
    Posts
    3

    Talking

    if you are trying to post a variable's value in the SQL statement, the simply concatenate the text with the variable in it. eg: "SELECT * FROM tblTable WHERE Field1='" & strVarName & "'"

    If you are trying to do something else, please be a little more specific as to what you are trying to achieve.

    Have Fun!

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241
    Here's what I did

    Declare @FirstQuery int

    SELECT @FirstQuery =(SELECT COUNT (*)as 'Your a Lammo' from dbo.vw_Lammo
    Where vendor_err='x' and created_dt>@FromDate)

    And this worked!!!

    Thanks for all the replies.

    This was a stored procedure doing a query to get a count.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width