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


Generate stored procedure parameter list based on table


Generate stored procedure parameter list based on table

Author
Message
Thomas Cournane
Thomas Cournane
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 52
Comments posted to this topic are about the item Generate stored procedure parameter list based on table
Paras@ISRC
Paras@ISRC
Forum Newbie
Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)Forum Newbie (8 reputation)

Group: General Forum Members
Points: 8 Visits: 58
It is very good stored procedure for tables having many columns and complex names.
One suggestion is - Instead of using default length of 5o for varchar use c.length column to get actual lenght.
Thomas Cournane
Thomas Cournane
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 52
Thank you Paras. I've made the enhancement.
tcooper-613006
tcooper-613006
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 3
I get "incorrect syntax near "c.length" when trying this.

Tim

paras.halingale (12/4/2009)
It is very good stored procedure for tables having many columns and complex names.
One suggestion is - Instead of using default length of 5o for varchar use c.length column to get actual lenght.

Thomas Cournane
Thomas Cournane
Forum Newbie
Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)Forum Newbie (9 reputation)

Group: General Forum Members
Points: 9 Visits: 52
Hey,
I've just had to use this again and have made some changes, I realise I only really need to the length of the column for text columns so here it is:

select c.name as name,
' = ',
'@' + c.name as _name_param,
c.name + '_DESC' as name_ordered,
t.name + '(' + cast(c.prec as varchar(50)) + ')' as [col_def],
coldefinition =
case t.name
when 'nvarchar' then 'nvarchar' + '(' + cast(c.prec as varchar(50)) + ')'
when 'varchar' then 'nvarchar' + '(' + cast(c.prec as varchar(50)) + ')'
when 'char' then 'char' + '(' + cast(c.prec as varchar(50)) + ')'
when 'nchar' then 'nchar' + '(' + cast(c.prec as varchar(50)) + ')'
else t.name
end
+ ' = NULL'
from sysobjects s
inner join sys.syscolumns c on s.id = c.id
inner join sys.types t on t.user_type_id = c.xtype
where s.xtype='U'
and s.name = 'PolicyZoneMembership'


Iwas Bornready
Iwas Bornready
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18430 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