on 10-09-2018 4:12 PM
Hi Guys,
Running ASE 16 SP02 PL03 on HP-UX, and trying this SQL:
declare @a tinyint
declare @e datetime
select @e=getdate() , @a=datepart(dw,@e)
select @e,@a
if @a in (1,3) print "OK"
The result is :
@e @a
Oct 9,2018 10:55:51 AM NULL /**--> null value **/
but then, if modifying the 3 line to :
select @e=getdate()
select @a=datepart(dw,@e)
The result is :
@e @a
Oct 9,2018:10:56:00 AM 3 /*->*value **/
OK
Any known behaviour?
Thank you
Regards
Jose
Hi Jose,
SQL handles each of the clauses independently, as if they were being processed in parallel. The results do not flow from left to right, each clause sees the same initial value for the variable.
This is documented here:
"Do not use a single select statement to assign a value to one variable and then to another whose value is based on the first. Doing so can yield unpredictable results."
Cheers,
-bret
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.