Path: csiph.com!usenet.pasdenom.info!gegeweb.org!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Erland Sommarskog Newsgroups: comp.databases.ms-sqlserver Subject: Re: Need help in SQL query Date: Tue, 11 Sep 2012 23:24:16 +0200 Organization: Erland Sommarskog Lines: 27 Message-ID: References: <9c4cab96-dd12-4947-94ff-f1ed31b2baee@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit Injection-Info: mx04.eternal-september.org; posting-host="9c1143bfab35549403b85d70ea1a57d8"; logging-data="3194"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+t/tjucyiuo8pdJRI3/IuQ" User-Agent: Xnews/2006.08.24 Mime-proxy/2.1.c.0 (Win32) Cancel-Lock: sha1:vPawzoDCKLAJfL6cKow2mtTKO6s= Xref: csiph.com comp.databases.ms-sqlserver:1279 Dinesh (dinesht15@gmail.com) writes: > But when I am executing the SP it is not returning the correct number of > name chnages. I have chnaged first name from Niki to Nikki and then > Nikki to Nikk and Nikk to Niki... Vijay to Sunny and Sunny to Niki. > > But here Sunny to Niki change is not appearing in my query result. It is > returning Niki to Niki as unchnaged row, which is not correct. Given the complexity of the code, are you surprised? Why is it using dynamic SQL in the first place? On a quick look of the procedure, I could see no reason for this. And if ou need to use dynamic SQL, why do you use unparameterised dynamic SQL? I have no time to dig into you query for the moment, but I would recommend that you remove the dynamic SQL, and then clean up the query so that it's easier to read. (Less uppercase could help too.) Maybe the error will be apparent as you work with the reformatting. -- Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se Links for SQL Server Books Online: SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx