SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 parameter declaration in sql
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

anjali5
Posting Yak Master

115 Posts

Posted - 06/22/2013 :  02:37:06  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 06/22/2013 :  02:43:33  Show Profile  Reply with Quote
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

115 Posts

Posted - 06/24/2013 :  12:52:29  Show Profile  Reply with Quote
Thank you.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52325 Posts

Posted - 06/24/2013 :  13:02:49  Show Profile  Reply with Quote
welcome

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

MuMu88
Aged Yak Warrior

547 Posts

Posted - 06/24/2013 :  13:50:44  Show Profile  Reply with Quote
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:



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;
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000