Sunday, August 31, 2014

If and Like with Stored Proc

USE [AdventureWorks2008R2]
GO
/****** Object:  StoredProcedure [dbo].[SP_countbyfirstName]    Script Date: 08/31/2014 08:49:39 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER proc [dbo].[SP_countbyfirstName] 
@firstname varchar(50)
as

Declare @cntno Int
select @cntno= COUNT(*)from Person.Person where FirstName like  @firstname +'%'

If (@cntno=95) 
begin
select * from Person.Person where FirstName like @firstname +'%'
end

If (@cntno<>95) 
begin
select * from Person.Person where FirstName like @firstname +'%'
end




No comments: