tsql works but store procedure with variable doesnt work

  • Hello,

    i just have a simple select statement, and i get the max value from one table that i use to at it to the where clause from another table, example:


    select Max(Order_ID)

    from dbo.orders

    then get that max id manully and copy it to the below select statement

    select *

    from customer_orders

    where orderID = 50

    however... when i create a store procedure and use a variable, like below:

    declare @MaxOrderID bigint

    select @MaxOrderID = Max(Order_ID)

    from dbo.orders

    select *

    from customer_orders

    where orderID = @MaxOrderID

    for some reason, the results come up blank, the orderID is also bigint... so i am not sure what i am missing... has that happen to anyone before?

     

     

    • This topic was modified 3 years, 7 months ago by  Siten0308.
  • Can you use Set instead of select

    Or rewrite your query

    Select * from customer_orders where order_id = (select max(order_id) from dbo.orders)

     

  • good call, let me see about setting it and re-write, will let you know.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply