Click here to Skip to main content
15,903,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello..

SQL
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[advSearch]
(
	@createdBy varchar(50) ,
	@subject varchar(200),
	@details nvarchar(MAX),
	@againstCompany varchar(100),
	@headOfficeAdd varchar(200),
	@deilveryOfficeAdd varchar(250)
	
)
AS

BEGIN
DECLARE @_s varchar(MAX)
DECLARE @_id int

select TOP 1 @_id = _id from tbl_User where _userName like '%'+ @createdBy+'%';

SELECT @_id;
SET NOCOUNT ON;

SET @_s='select * from tbl_Alert where isActive=1';

if @createdBy<>''
	BEGIN 

		SET @_s=@_s+' and createdBy ='+@_id;
	END 

if @subject<>''
	BEGIN 

		SET @_s=@_s+' and subject like ''%'+ @subject+'%''';
	END 

if @details<>''
	BEGIN 

		SET @_s=@_s+' and details like ''%'+ @details+'%''';
	END

if @againstCompany<>''
	BEGIN 

		SET @_s=@_s+' and againstCompany like ''%'+ @againstCompany+'%''';
	END

if @headOfficeAdd<>''
	BEGIN 

		SET @_s=@_s+' and headOfficeAdd like ''%'+ @headOfficeAdd+'%''';
	END

if @deilveryOfficeAdd<>''
	BEGIN 

		SET @_s=@_s+' and deilveryOfficeAdd like ''%'+ @deilveryOfficeAdd+'%''';
	END

exec(@_s)

END


SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON


What is mistake in query. please help. . .

i got error like

Msg 245, Level 16, State 1, Procedure advSearch, Line 28
Conversion failed when converting the varchar value 'select * from tbl_Alert where isActive=1 and createdBy =' to data type int.
Posted
Comments
SLNS001 23-May-13 5:19am    
It is executed in SQL Server. Didn't get any error.
[no name] 23-May-13 5:21am    
above error is run time error .

Change
SQL
SET @_s=@_s+' and createdBy ='+@_id;

To
SQL
SET @_s=@_s+' and createdBy ='+CONVERT(VARCHAR,@_id,0);
 
Share this answer
 
instead of
SQL
SET @_s=@_s+' and createdBy ='+@_id;

write
SQL
SET @_s=@_s+' and createdBy =''' + convert(varchar,@_id) + '''';

Happy Coding!
:)
 
Share this answer
 
change like this

SET @_s=@_s+' and createdBy ='+ convert(varchar,@_id);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900