SQL Server - With Clause -


i creating query containing clause. so:

with temp (pin) (     select t1.field_val table1 t1 t1.primkey = '9549' , t1.field2 = 10 )  select wfu.ss_peid, wfu2.ifas_userid temp temp     inner join table2 t2 on temp.pin = t2.pin     inner join table3 t3 on t2.id = t3.id     left outer join table3b t3b on t3.id = t3b.id t3.asstid not null or wfu.asstid != '' 

in select statement in clause above, have t1.primkey hard coded '9549'. when change use parameter passed in @var so:

with temp (pin) (     select t1.field_val table1 t1 t1.primkey = @var , t1.field2 = 10 )  select wfu.ss_peid, wfu2.ifas_userid temp temp     inner join table2 t2 on temp.pin = t2.pin     inner join table3 t3 on t2.id = t3.id     left outer join table3b t3b on t3.id = t3b.id t3.asstid not null or wfu.asstid != '' 

it no longer works. why wouldn't select statement in clause work parameter variable in it?

...

edit:

:) apologies. in head seemed understood not happening. value hard coded t1.primkey = '9549' results query. when change use parameter of stored procedure, t1.primkey = @var no results returned.

as far setting value of parameter, in stored procedure parameter passed in application or when execute procedure ssms. have tested in new query window following declare , set statement:

declare @var varchar; set @var = '9549'; 

i posted same question on msdn here: https://social.msdn.microsoft.com/forums/en-us/0705dcd8-d05d-4fa6-b2d0-01570cd40186/sql-server-with-expression?forum=transactsql

it's odd had never run scenario before , had set length of varchar parameters or used nvarchar. parameter @var varchar or in code above declare @var varchar default length 1. when set variable '9549' getting '9'. thought leaving open meant length determined when value passed in.

hope helps else someday :p.


Comments

Popular posts from this blog

java - Could not locate OpenAL library -

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

sorting - opencl Bitonic sort with 64 bits keys -