----------------------------------------------------------- New Message on BDOTNET
----------------------------------------------------------- From: Madhav_S9 Message 5 in Discussion Create a Stored Procedure or Function using following script, and pass tablename and NoOfColumns as Input Parameters. You problem is solved :) Have a nice time. Declare @TableName nvarchar(1000) Declare @NoOfColumns Int Set @NoOfColumns = 3 Set @TableName = 'Stores' Declare @ID INT Declare @SqlString nvarchar(3000), @SqlString1 nvarchar(3000) Set @SQLString = 'Select ' Select @ID = id From SYSOBJECTS WHERE xtype = 'U' and Name = @TableName Declare @SQlParameters nvarchar(1000) Set @SqlParameters = N'@SQLString nvarchar(3000) OUTPUT, @ID Int' Set @SqlString1 = 'Select Top ' + Cast(@NoOfColumns as varchar(5)) + ' @SQLString = @SQLString + '' '' + name + '','' From SYSCOLUMNS WHERE id = @ID order by colid' PRINT @SQLString1 Exec sp_executesql @SqlString1, @SqlParameters, @SqlString OUTPUT, @ID SeT @SQLString = Left(@SqlString, Len(@SqlString) - 1) + ' From ' + @tablename Exec sp_executesql @SqlString ----------------------------------------------------------- To stop getting this e-mail, or change how often it arrives, go to your E-mail Settings. http://groups.msn.com/BDOTNET/_emailsettings.msnw Need help? If you've forgotten your password, please go to Passport Member Services. http://groups.msn.com/_passportredir.msnw?ppmprop=help For other questions or feedback, go to our Contact Us page. http://groups.msn.com/contact If you do not want to receive future e-mail from this MSN group, or if you received this message by mistake, please click the "Remove" link below. On the pre-addressed e-mail message that opens, simply click "Send". Your e-mail address will be deleted from this group's mailing list. mailto:[EMAIL PROTECTED]
