Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
fh200300us
Starting Member
28 Posts |
Posted - 2008-02-08 : 11:17:02
|
| I have the D-SQL like thisALTER PROCEDURE [dbo].[sp_getColumnNameList] -- Add the parameters for the stored procedure here @tablename nvarchar(50)='Fix' -- RETURNS nvarChar(500) ASBEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; declare @StrSQL nvarchar(500) declare @params nvarchar(500) declare @StrcolumnList nvarchar(500) Set @StrSQL = ' SELECT @strColumnName = @strColumnName + COLUMN_NAME +' + ''' , '' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME ='''+ @tablename +'''' + ' SELECT @columnList= @strColumnName SELECT @columnList ' select @params = N'@columnList nvarchar(500) OUTPUT, ' + N'@strColumnName nvarchar(500)' print @StrSQL EXEC sp_executesql @StrSQL,@params, @columnList=@StrcolumnList OUTPUTthe error like this Msg 8178, Level 16, State 1, Line 0Parameterized Query '(@columnList nvarchar(500) OUTPUT, @strColumnName nvarchar(500' expects parameter @strColumnName, which was not supplied.What is the problem?Thanks, |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-02-08 : 11:35:09
|
There are several issues with what you posted. Here is a simpler solution:ALTER PROCEDURE [dbo].[sp_getColumnNameList] @tablename nvarchar(50)='Fix'ASdeclare @strColumnList nvarchar(500)select @strColumnList = coalesce(@strColumnList + ', ' + column_name, column_name)from information_schema.columnswhere table_name = @tableNameorder by ordinal_positionselect @strColumnListgo Be One with the OptimizerTG |
 |
|
|
fh200300us
Starting Member
28 Posts |
Posted - 2008-02-08 : 11:43:25
|
| Thanks you very much. |
 |
|
|
|
|
|