November 16, 2005 at 4:44 pm
Hi,
I've a problem with this query :
DECLARE @salesDate DATETIME
SELECT salesPrice
FROM salesProduct
WHERE salesDate = (
SELECT @salesDate = MIN( salesDate )
FROM salesProduct
WHERE saleProductId = 4
)
AND salesProductId = 4
The error is :
Servidor: mensaje 170, nivel 15, estado 1, línea 5
Línea 5: sintaxis incorrecta cerca de '='.
I looked for the error 170, it's basically a sintax error, but if I execute the instruction without a subquery it runs... Like this ...
DECLARE @salesDate DATETIME
SELECT @salesDate = MIN( salesDate )
FROM salesProduct
WHERE salesProductId = 4
SELECT Result = @salesDate
It prints 2005-08-10 18:12:34.543
So, what's wrong ? It's posible to use variables in subqueries ?
I apreciate any help, thanks ...
November 16, 2005 at 4:56 pm
DECLARE @salesDate DATETIME
DECLARE @salesPrice ???
SELECT @salesDate = sp1.salesDate, @salesPrice = sp1.salesPrice
FROM salesProduct sp1
WHERE sp1.salesDate = (
SELECT MIN( sp2.salesDate )
FROM salesProduct sp2
WHERE sp2.saleProductId = sp1.saleProductId
)
AND sp1.salesProductId = 4
November 17, 2005 at 7:41 am
Tanks SlyStyx,
I solve my problem, I get the value in the first select.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply