SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Generate stored procedure parameter list based on table order by table


Generate stored procedure parameter list based on table order by table

Author
Message
jplebrasseur
jplebrasseur
SSC Rookie
SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)

Group: General Forum Members
Points: 33 Visits: 7
Comments posted to this topic are about the item Generate stored procedure parameter list based on table order by table
Brett Phipps
Brett Phipps
Mr or Mrs. 500
Mr or Mrs. 500 (599 reputation)Mr or Mrs. 500 (599 reputation)Mr or Mrs. 500 (599 reputation)Mr or Mrs. 500 (599 reputation)Mr or Mrs. 500 (599 reputation)Mr or Mrs. 500 (599 reputation)Mr or Mrs. 500 (599 reputation)Mr or Mrs. 500 (599 reputation)

Group: General Forum Members
Points: 599 Visits: 230
Customer table? Change what customer table?
Rob Maurer
Rob Maurer
SSC-Enthusiastic
SSC-Enthusiastic (126 reputation)SSC-Enthusiastic (126 reputation)SSC-Enthusiastic (126 reputation)SSC-Enthusiastic (126 reputation)SSC-Enthusiastic (126 reputation)SSC-Enthusiastic (126 reputation)SSC-Enthusiastic (126 reputation)SSC-Enthusiastic (126 reputation)

Group: General Forum Members
Points: 126 Visits: 359
With a few changes, it runs on SQL2000: (table names go into the WHERE clause on line 35, eg 'tIndividuals') - Merci, Jean-Pierre - RM


--Jean-Pierre Lebrasseur
--date 04-12-2009
--this script give you columns parameters order by table name and ordinal position by table.

declare @sqlstmt char(500)
declare @name char(50)
declare @coldefinition char(50)

declare CreateParam cursor for
select 'declare @' + c.name, col_definition =
case t.name
when 'bigint' then 'bigint'
when 'int' then 'int'
when 'smallint' then 'smallint'
when 'tinyint' then 'tinyint'
when 'bit' then 'bit'
when 'decimal' then 'decimal'
when 'numeric' then 'numeric'
when 'money' then 'money'
when 'smallmoney' then 'smallmoney'
when 'float' then 'float'
when 'real' then 'real'
when 'datetime' then 'datetime'
when 'smalldatetime' then 'smalldatetime'
when 'sql_variant' then 'sql_variant'
when 'timestamp' then 'timestamp'
when 'uniqueidentifier' then 'uniqueidentifier'
when 'xml' then 'xml'
else t.name + '(' + cast(c.prec as varchar(50)) + ')'
end
from sysobjects s
inner join syscolumns c on s.id = c.id
inner join systypes t on t.xusertype = c.xtype
where s.xtype='U' and
(s.name = 'tIndividuals' or s.name = 'ProductStatus' or s.name = 'ProductBrandCode')
order by s.name , c.colid

open CreateParam

fetch next from CreateParam into @name, @coldefinition

while @@fetch_status = 0
begin
set @sqlstmt = ''
set @sqlstmt = rtrim(@sqlstmt) + rtrim(@name) + ' ' + rtrim(@coldefinition)

print rtrim(@sqlstmt)
fetch next from CreateParam into @name, @coldefinition
end

close CreateParam
deallocate CreateParam



go


Iwas Bornready
Iwas Bornready
SSC-Dedicated
SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)SSC-Dedicated (31K reputation)

Group: General Forum Members
Points: 31928 Visits: 885
Thanks for the script.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search