Re: help with stored procedure which returns an OUTPUT value



Vic (vikrantp@xxxxxxxxx) 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@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.



Relevant Pages

  • Re: Preventing SQL Injection attacks
    ... things handled by replacing all single quotes with two single quotes, ... clever hackers have still managed to find a way to drop columns ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (comp.databases.ms-sqlserver)
  • Re: FTI, Searching and other Filters
    ... No matter what I specify for a search condition, ... "SQL SERVER DBA"') ... Remove the FTI from the table. ... Add an OfficeID column to the table and populate it. ...
    (microsoft.public.sqlserver.fulltext)
  • Online Training in SQL DBA
    ... Maripax Offers Online Training in SQL DBA ... Introduction to Microsoft SQL Server ... Creating and Implementing Database Objects ... Specify column details. ...
    (comp.sys.atari.8bit)
  • Re: Linked Server - Force Translate
    ... I had the same issue when using a connection string with same ... > see sp_addlinkedserver in Books Online for details. ... > You can also use OPENROWSET and specify a connection string with it. ... > Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se ...
    (microsoft.public.data.oledb)
  • Re: bcp accent problem
    ... For -C you specify a code page, not a collation, as I recall. ... file is in the ANSI code page, specify -C ANSI or -C RAW. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.sqlserver.tools)