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
 SQL Server 2000 Forums
 SQL Server Development (2000)
 declaring datatypes using a column reference

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-02-03 : 08:53:40
Don Juan writes "

Is it possible to declare a variable with a datatype that references a column's datatype?

such as:
DECLARE @SomeVar MyTable.SomeColumn
As an Oracle developer (please keep reading :) ) I'm accustomed to being able to do this with the %TYPE attribute:
declare
v_some_var my_table.some_column%TYPE;
begin
select some_column
into v_some_var
from my_table
where another_column = 'boo';
end;
The functionality offered by %TYPE means that if the developer needs to, for instance, alter my_table and make some_column larger, then v_some_var will automatically assume the new datatype, and the select statement will continue to work without the developer having to hunt thru the code and manually resize some_column, and recompile. However v_some_var was given a 'concrete' datatype (like I'm having to do now in SQL Server) and somebody made some_column larger, then the select statement could possibly fail because now v_some_var wouldn't be large enough to hold the select'ed value.

Is something similar to %TYPE possible in SQL Server?

<edit> to fix display </edit>

Edited by - robvolk on 02/03/2003 13:14:01

X002548
Not Just a Number

15586 Posts

Posted - 2003-02-03 : 09:19:29
Nope....not to mu knowledge, also there is nothing like reference cursors...

Its a strange new land you've journeyed in to....

make Books Online (BOL for short) your friend.

You do you need it bu the way? Don't you know the object definition taht your calling/ being called by?

Good Luck

Brett

8-)

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-02-03 : 14:52:39
quote:
Don't you know the object definition taht your calling/ being called by
I agree with this assessment. It's always bad to write code in such a way that allows things like figuring out which datatype is which, or setting it up to allow arbitrary changes, later on or even during runtime. Regardless of the convenience, it's too easy to have bugs crop up because not enough forethought was given to writing the code or designing the database properly. Altering a table structure SHOULD NOT be an easy, carefree/careless act.

You may not think so, but NOT having this kind of feature in SQL Server is going to make you a better coder.

Go to Top of Page
   

- Advertisement -