Marius0188
asked on
MS SQL 2005 :: SET Variable Value Dynamically Based On Select Field's Value
Dear Experts,
Is it possible to assign different values to a parameter in a SQL statement based on your select field's value.
Please see code snipped for a clearer understanding.
Is it possible to assign different values to a parameter in a SQL statement based on your select field's value.
Please see code snipped for a clearer understanding.
DECLARE @P INT
SELECT
P2.PartNo, P2.GroupingCode, P2.Code, P2.Qty,
CASE WHEN P2.Qty > 10 THEN
SET @P = 10000
ELSE
SET @P = -99
END,
@P AS VarValue
FROM
tblPickingList P2
you cannot SELECT at SET in the same statement.
anyhow, do you really need the @p?
SELECT
P2.PartNo, P2.GroupingCode, P2.Code, P2.Qty,
CASE WHEN P2.Qty > 10
THEN 10000
ELSE -99
END AS VarValue
FROM
tblPickingList P2
ASKER
Yes, I just use it in that simple example for explanation purposes.
Where I will be using it it could ease my life a lot. :)
Where I will be using it it could ease my life a lot. :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
What do you mean with "just a single value" ?
Thanks for quick replies.
:)
Thanks for quick replies.
:)
as I wrote: just 1 single value.
you did not really explain what you actually try to achieve, so I can only give "guessings" ...
you did not really explain what you actually try to achieve, so I can only give "guessings" ...