January 11, 2017 at 5:23 pm
I'm wondering why i cannot grab a column value and use it down the line in my sql statement/stored procedure
I have something like this:
select o.orderid, o.salesproduct , i.saledate from orders as o,ordersinfo as i where o.ordernum = i.archivednum group by o.orderid, o.salesproduct,i.salesdate
Declare @oid uniqueidentifier
set @oid = o.orderid
select v.vendortype from vendorsorders as v where v.orderid = @oid
whereas @oid is not legit, renders "multipart identifier could not be bound"
? 🙁
thanks for all help
Zo
January 11, 2017 at 6:54 pm
set @oid = o.orderid
What is "o.orderid"?
Did you forget about FROM part?
_____________
Code for TallyGenerator
January 11, 2017 at 7:07 pm
Hypothetically the orderid would also be copied from orders table to vendororders table sometime after the process of the order history
HTH, thanks
January 11, 2017 at 8:15 pm
Firstly, there probably is a logic error with the code you included. The first SELECT statement would return records for many orders. The scalar variable you are using (@oid) can store a single value only (i.e. it would only store one ordered but the first SELECT statement could return thousands of different orders. Which order do you want to use to lookup the vendor type ?
Perhaps a single query such as the one below might give you what you are after using a single query
select v.vendortype, o.orderid, o.salesproduct , i.saledate
from orders as o
INNER JOIN ordersinfo as i
ON o.ordernum = i.archivednum
INNER JOIN vendorsorders as v
ON v.orderid = o.orderid
group by v.vendortype, o.orderid, o.salesproduct,i.salesdate
January 12, 2017 at 3:58 pm
happycat59 - Wednesday, January 11, 2017 8:15 PMFirstly, there probably is a logic error with the code you included. The first SELECT statement would return records for many orders. The scalar variable you are using (@oid) can store a single value only (i.e. it would only store one ordered but the first SELECT statement could return thousands of different orders. Which order do you want to use to lookup the vendor type ?Perhaps a single query such as the one below might give you what you are after using a single queryselect v.vendortype, o.orderid, o.salesproduct , i.saledate from orders as oINNER JOIN ordersinfo as i ON o.ordernum = i.archivednum INNER JOIN vendorsorders as vON v.orderid = o.orderidgroup by v.vendortype, o.orderid, o.salesproduct,i.salesdate
Thanks for assist, yes the requirement changed somewhat and are going to parse the information at the application level, but I needed to see if I can retain each row and then extend more data correctly correlating to the given row, but the logic needed more filtering out of the scope of what I perceived could happen.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply