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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 parameter declaration in sql

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 know
in sql, I can write the type like int or varchar, but is it possible to do something like tablename.columnName so

This is one of my parameter in oracle

p_number in rep_header.rep_num%type

I need something equivalent in sql

any help will be appreciated.

Thanks.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-22 : 02:43:33
Nope. There's no equivalent method

The best available alternative is User Defined Type

http://www.mssqltips.com/sqlservertip/1628/sql-server-user-defined-data-types-rules-and-defaults/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

anjali5
Posting Yak Master

121 Posts

Posted - 2013-06-24 : 12:52:29
Thank you.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-06-24 : 13:02:49
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

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]
Go to Top of Page
   

- Advertisement -