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 |
anjali5
Posting Yak Master
121 Posts |
Posted - 2013-06-22 : 02:37:06
|
Hi All, In oracle, I can declare the parametrs type using the tablename.columnName type. Can I do something like this on sql. I knowin sql, I can write the type like int or varchar, but is it possible to do something like tablename.columnName soThis is one of my parameter in oracle p_number in rep_header.rep_num%typeI need something equivalent in sqlany help will be appreciated.Thanks. |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
anjali5
Posting Yak Master
121 Posts |
Posted - 2013-06-24 : 12:52:29
|
Thank you. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-06-24 : 13:02:49
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
MuMu88
Aged Yak Warrior
549 Posts |
Posted - 2013-06-24 : 13:50:44
|
May not be the most elegant or efficient way but if you want to get the data type of an existing column you can create a dynamic query like this:[CODE]DECLARE @mydecl VARCHAR(MAX);SET @mydecl = '' + (SELECT TOP 1 DATA_TYPE from [AdventureWorks2012].INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'NAME') + '(' + CAST((SELECT TOP 1 CHARACTER_MAXIMUM_LENGTH from [AdventureWorks2012].INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'NAME') AS VARCHAR) + ');' SELECT @mydecl;SET @mydecl = 'DECLARE @myname ' + (SELECT TOP 1 DATA_TYPE from [AdventureWorks2012].INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'NAME') + '(' + CAST((SELECT TOP 1 CHARACTER_MAXIMUM_LENGTH from [AdventureWorks2012].INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'NAME') AS VARCHAR) + '); ' + 'DECLARE @myProductCategoryID ' + (SELECT TOP 1 DATA_TYPE from [AdventureWorks2012].INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'ProductCategoryID') + ';';SELECT @mydecl;[/CODE] |
|
|
|
|
|