c# - How to pass variable (Alias) into where condition SQL -
goodday all,
i want pass 'coalesce(mdt.deptname,dd5.name) departname' condition. error shows invalid column. possibilties ? below code:
select op_id, dd.name unit, dd1.name freq, dd2.name calc, coalesce(mdt.deptname, dd5.name) departname, coalesce(co.yearlytarget + ' ' + dd3.name, co.yearlytarget)as yearlytarget, co.pastyearresult, co.weight, co.project, co.description, co.datecreated, mdt.weightvalue [mbo].[dbo].[m_newcaloprt] co left join [mbo].[dbo].[m_ddl] dd on co.unit_ddl = dd.d_id left join [mbo].[dbo].[m_ddl] dd1 on co.freq_ddl = dd1.d_id left join [mbo].[dbo].[m_ddl] dd2 on co.calc_ddl = dd2.d_id left join [mbo].[dbo].[m_user] on co.uid = us.id left join [mbo].[dbo].[m_user] us1 on us1.deptid = us.deptid left join [mbo].[dbo].[m_ddl] dd5 on us1.deptid = dd5.d_id left join [mbo].[dbo].[m_multipledept] mdt on mdt.projectid = co.op_id left join [mbo].[dbo].[m_ddl] dd3 on co.calcsymbol = dd3.d_id departname = '' , isactive = 0 , isverifed = 1
i want use code c#. please advise
you cannot use alias
name in where
clause. use original columns
where coalesce(mdt.deptname, dd5.name) = '' , isactive = 0 , isverifed = 1
this how query logically processed
1. 2. on 3. outer 4. --here 5. group 6. cube | rollup 7. having 8. select --here 9. distinct 10 order 11. top
since where
clause processed before select
not have alias
name in where
clause
Comments
Post a Comment