Uri Dimant
3/28/2007 12:53:00 PM
Again
As you said if you build SQL 'directly' it works fine, OK now just PRINT
@sql (part of building) and compare with 'directly' build SQL, that's all.
<marckus@gmail.com> wrote in message
news:1175085785.370251.233540@o5g2000hsb.googlegroups.com...
> On Mar 28, 2:40 pm, marc...@gmail.com wrote:
>> On Mar 28, 2:33 pm, "Uri Dimant" <u...@iscar.co.il> wrote:
>>
>> > SELECT @sql = 'SELECT @sTitle = f.title, @sName = f.name, @sPath =
>> > f.path, @sBody = c.designBody, @sDate = c.lastModify
>> > FROM files AS f INNER JOIN contents AS c ON c.fileId = f.id WHERE
>> > (f.status = 2) AND (c.designBody LIKE @sWord)
>> > ORDER BY c.lastmodify DESC';
>>
>> > PRINT @sql
>>
>> > Do you have nothing?
>>
>> set ANSI_NULLS ON
>> set QUOTED_IDENTIFIER ON
>> GO
>> ALTER PROCEDURE [dbo].[doSearch]
>> -- Add the parameters for the stored procedure here
>> @searchWord nvarchar(4000)
>> AS
>> BEGIN
>> -- SET NOCOUNT ON added to prevent extra result sets from
>> -- interfering with SELECT statements.
>> SET NOCOUNT ON;
>>
>> DECLARE @sql nvarchar(4000);
>> DECLARE @ParmDefinition nvarchar(500);
>> DECLARE @searchTitle nvarchar(500);
>> DECLARE @searchName nvarchar(500);
>> DECLARE @searchPath nvarchar(500);
>> DECLARE @searchBody nvarchar(4000);
>> DECLARE @searchDate DateTime;
>>
>> SELECT @sql = 'SELECT @sTitle = f.title, @sName = f.name, @sPath
>> =
>> f.path, @sBody = c.designBody, @sDate = c.lastModify
>> FROM files AS f INNER JOIN contents AS c ON c.fileId = f.id WHERE
>> (f.status = 2) AND (c.designBody LIKE @sWord)
>> ORDER BY c.lastmodify DESC';
>> SET @ParmDefinition = N'@sWord nvarchar(4000), @sTitle
>> nvarchar(500)
>> OUTPUT,
>> @sName
>> nvarchar(500) OUTPUT, @sPath nvarchar(500) OUTPUT,
>> @sBody
>> nvarchar(4000) OUTPUT, @sDate DateTime OUTPUT';
>>
>> EXEC sp_executesql @sql, @ParmDefinition, @sWord = @searchWord,
>> @sTitle = @searchTitle OUTPUT, @sName = @searchName OUTPUT, @sPath =
>> @searchPath OUTPUT, @sBody = @searchBody OUTPUT, @sDate = @searchDate
>> OUTPUT;
>> PRINT @sql
>> END
>>
>> That is the Stored Procedure and the content in the searchword is
>> (that i am using to test with)
>>
>> USE [test]
>> GO
>>
>> DECLARE @return_value int
>>
>> EXEC @return_value = [dbo].[doSearch]
>> @searchWord = N'%word% OR c.designBody LIKE %word1%'
>>
>> SELECT 'Return Value' = @return_value
>>
>> GO
>
> If i skip the SP and build the SQL query directly in the code, then it
> can execute the query fine and give me the right results.
>