Reputation: 151
I have SQL statement like these:
DECLARE @bDate DATE;
SET @bDate = SELECT birth_date FROM person WHERE id='1';
SELECT @bDate;
But the result always is an error:
Must Declare the scalar variable for @bDate
Can anyone help me? I have asked from any forum but the result are same.
Thanks
Upvotes: 0
Views: 3970
Reputation: 24813
Your syntax is wrong for the SET
It should be
DECLARE @bDate DATE;
SET @bDate = (SELECT birth_date FROM person WHERE id='1');
SELECT @bDate;
OR, you can use SELECT
DECLARE @bDate DATE;
SELECT @bDate = birth_date FROM person WHERE id='1';
SELECT @bDate;
Upvotes: 5