View Single Post

   
  #4 (permalink)  
Old 03-04-2008, 06:23 AM
Erland Sommarskog
 
Posts: n/a
Default Re: help with stored procedure which returns an OUTPUT value

Vic (vikrantp@gmail.com) writes:
> Also the print @sql isn't showing values of @db. So I tried to modify
> the select statement by modifying the the single quotes (') in the
> line then I see the error as @db not declared or something.


You have:

> N' FROM @db.INFORMATION_SCHEMA.COLUMNS '+


I don't think this can ever be legal T-SQL. In any case it can never mean
what you intended. You cannot specify the database name through a
variable, but you have to inline it:

N' FROM '*+ quotename(@db) + '.INFORMATION_SCHEMA.COLUMNS '+

> Also Exec sp_executesql @sql, @params, 'TestData', 'accounting', '11'
> is that how I call sp_executesql?


The first parameter is the SQL statement. The second is the parameter
list. The remaining are the parameters as specified in your parameter
list.

> N' COLUMN_NAME LIKE @fieldnumber-% '


This is not going to end happily. - is a numeric operator, but % will not
convert to an integer. You need:

> N' COLUMN_NAME LIKE @fieldnumber + ''-%'' '





--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Reply With Quote