Count(*) and Like

From: kk (anonymous_at_discussions.microsoft.com)
Date: 07/26/04


Date: Mon, 26 Jul 2004 04:34:47 -0700

I have a SQL statement like the below listed inside a
stored procedure.
-------------------------------
declare @cnt int
declare name varchar(250)
set @name = 'aaa'

Select @cnt = count(*) from table1
where name like @name + '%'

select @cnt
--------------------------------
@cnt is always zero, irrespective of how I change the
query even though I have more than one row in that
table corresponding to the Like.

The same statement works fine from the query analyzer.

Please advise.



Relevant Pages

  • RE: How do I..
    ... Here is the results from Query Analyzer: ... Must declare the variable '@j'. ... >> How do I write this as a SQL Statement? ...
    (microsoft.public.sqlserver.programming)
  • 22 seconds via QA and sub-second under 1 SSMS
    ... why is it that this sql statement ... DECLARE @SQL_BULK_INSERT VARCHAR ... takes 22 seconds via SQL 2000 query analyzer; but it runs in under a ...
    (microsoft.public.sqlserver)
  • Re: Another Drop List question
    ... > Dim Name, Email ... > 'declare SQL statement that will query the database ... to make sure the sql statement contains what you expect: ... run as-is in your database's query execution tool ...
    (microsoft.public.inetserver.asp.general)
  • Re: Accessing value from dynamic SQL
    ... DECLARE @t varchar ... DECLARE @SqlStatement nvarchar ... N'@c int OUT', ... > I need to access the value of dynamic SQL statement within a stored proc. ...
    (microsoft.public.sqlserver.programming)
  • Re: Count(*) and Like
    ... Can you please post the code for stored procedure. ... > I have a SQL statement like the below listed inside a ... > declare @cnt int ... > declare name varchar ...
    (microsoft.public.sqlserver.mseq)