Hi All,
I have 1 query in sql server.
DECLARE @sqlWhere VARCHAR(MAX)
SET @sqlWhere = 'flg_active = 1 order by CreatedDate'
Select * from TableName1 where @sqlWhere
Is it possible with out dynamic SQL.
Thanks,
Jitendra Patel
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pravin MoreRank #1,419 · 1.2K reputationPosted Jan 22, 2012, 11:11 PM EST
you need to give it like.............
DECLARE @sqlWhere VARCHAR(MAX)
DECLARE @qry VARCHAR(MAX)
SET @sqlWhere = 'flg_active = 1 order by CreatedDate'
set @qry='Select * from TableName1 where'+ @sqlWhere
exec(@qry)
Thanks,
Pravin.
Jitendra Patel138 reputationPosted Jan 22, 2012, 11:42 PM EST
it's a correct answer but I don't use dynamic Sql
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 23, 2012, 1:05 AM EST
is there any restriction not use dynamic sql.
are u using which technology> i.e. pure SQL or ADO.net?
Jitendra Patel138 reputationPosted Jan 23, 2012, 2:04 AM EST
I am using sql server 2008.
I have 6500000 records and when I am useing dynamic sql then it's performance is very slow.
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 23, 2012, 2:55 AM EST
that is correct you will retrive 6500000 rows.
but i think when you use exec, it will not effect ur performance.
Jitendra Patel138 reputationPosted Jan 23, 2012, 3:57 AM EST
if there are not any other option then I will continue with exec (dynamic sql)
Thanks for co-operate.
Pravin MoreRank #1,419 · 1.2K reputationPosted Jan 23, 2012, 6:39 PM EST
i dont think writing query in string and then exec will make delay compare to normal query.performance will be same.