Re: Different Row Counts From Two Virtually Identical Queries
From: Aaron Bertrand [MVP] (aaron_at_TRASHaspfaq.com)
Date: 03/19/04
- Next message: Dragan BAbovic: "RE: Update lock seems to hang"
- Previous message: Delbert Glass: "Re: Optimizer question"
- In reply to: Bruce Rose: "Different Row Counts From Two Virtually Identical Queries"
- Next in thread: Xavier Lazard: "RE: Different Row Counts From Two Virtually Identical Queries"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 19 Mar 2004 11:54:22 -0500
Query 1 is looking for the following value:
'smith'
If you are passing your value directly into a variable, you don't need to
escape/delimit the string.
-- Aaron Bertrand SQL Server MVP http://www.aspfaq.com/ "Bruce Rose" <brose@snl.com> wrote in message news:u%23zVoDdDEHA.1456@TK2MSFTNGP09.phx.gbl... > Hi all, > > Well I am baffled. Can anyone tell me why these two virtually same > queries return different counts? Query 1 returns a count = 0 while > query 2 returns a count = 1. I have listed some very simple code you > can try in order to see what I am talking about. > > create table ##junk ( LastName nvarchar(100) ) > go > insert into ##junk values ('smith') > go > > declare @s varchar(4000) > declare @sLastName nvarchar(100) > select @sLastName = '''smith''' > > select count1 = count(*) FROM ##junk > WHERE (LastName = @sLastName ) > > select @s = > 'select count2 = count(*) FROM ##junk ' + > 'WHERE (LastName = ' + @sLastName + ') ' > exec (@s) > > drop table ##junk > go > > Any insight into this anomaly is appreciated. > > Thanks, > Bruce > > > > Hi all, > > Well I am baffled. Can anyone tell me why these two virtually same > queries return different counts? Query 1 returns a count = 0 while > query 2 returns a count = 1. I have listed some very simple code you > can try in order to see what I am talking about. > > create table ##junk ( LastName nvarchar(100) ) > go > insert into ##junk values ('smith') > go > > declare @s varchar(4000) > declare @sLastName nvarchar(100) > select @sLastName = '''smith''' > > select count1 = count(*) FROM ##junk > WHERE (LastName = @sLastName ) > > select @s = > 'select count2 = count(*) FROM ##junk ' + > 'WHERE (LastName = ' + @sLastName + ') ' > exec (@s) > > drop table ##junk > go > > Any insight into this anomaly is appreciated. > > Thanks, > Bruce > > > > > > *** Sent via Developersdex http://www.developersdex.com *** > Don't just participate in USENET...get rewarded for it!
- Next message: Dragan BAbovic: "RE: Update lock seems to hang"
- Previous message: Delbert Glass: "Re: Optimizer question"
- In reply to: Bruce Rose: "Different Row Counts From Two Virtually Identical Queries"
- Next in thread: Xavier Lazard: "RE: Different Row Counts From Two Virtually Identical Queries"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|