Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Table look like below

SQL
CREATE TABLE [dbo].[STS_ADDRESS_BOOK](
         [AB_NAME] [varchar](100),
         [AB_EMAIL] [varchar](100),
         [AB_FAX] [varchar](100),
         [AB_ID] int NOT NULL IDENTITY(1,1) CONSTRAINT primarykey PRIMARY KEY) 	   


-----------------------------------------------------------------------------
sp,


GO
IF OBJECT_ID ('dbo.selectAddressBookInformation1')IS NOT NULL
DROP PROC  selectAddressBookInformation1
GO

CREATE PROC selectAddressBookInformation1 @columnvalue varchar(100),
@searchword varchar(100)
AS

exec ('select* from STS_ADDRESS_BOOK where CONTAINS('+@columnvalue+','+@searchword+')')

-----------------------------------------------------------------------------
this  command executed successfully.But the problem is on executing the sp

using, 
-----------------------------------------------------------------------------
exec selectAddressBookInformation1 @columnvalue=[AB_NAME], @searchword='hari'


give error as Incorrect syntax near 'hari'.

why?plz help me?...
Posted
Updated 24-Sep-12 19:40pm
v3

try sp_executeSQL, you have the flexibility to add parameters also :

http://msdn.microsoft.com/en-us/library/ms175170(v=sql.105).aspx[^]

Building Dynamic SQL In a Stored Procedure[^]
 
Share this answer
 
v2
hii,
replace this
exec ('select* from STS_ADDRESS_BOOK where CONTAINS('+@columnvalue+','+@searchword+')')

with

exec ('select* from STS_ADDRESS_BOOK where CONTAINS('+@columnvalue+','''+@searchword+''')')

your problem will solve

have happy coding
 
Share this answer
 
v2
Comments
hasbina 25-Sep-12 4:14am    
Thanks Ganesh...Thank you very much...
Ganesh Nikam 25-Sep-12 4:29am    
always welcome

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