coming from an oracle background, im quite having lots of gripes (recently) trying to get things to work in SQL Server, and i would really appreciate help/some advice.
recently, ive come across this article comparing oracle's pl/sql and sql server's t-sql:
and i would love if someone could show to implement "anchored declarations".
to quote from the article:
---
To gain an understanding of how PL/SQL can ease your coding, consider the following—unfortunately, common—scenario. Suppose you have a column in a table that is declared as a char (50). In all your stored procedures that reference this column and store values from it in a variable, you also declare your variables to be char (50). Now, after you've finished your umpteenth procedure, you find out that the column needs to be extended to a char (100). In T-SQL, you (or in fact, me during a very long afternoon session several weeks ago) are in for a lot of searching and replacing the char (50) declarations with char (100). But in PL/SQL, you can simply use what's called an anchored declaration and avoid the problem.
An anchored declaration allows you to declare your variable as being of whatever type the particular column in the table is. For example, emp_id emp.empno%TYPE declares a variable called emp_id, which is the same type as the column empno in the emp table. If I change the column type in the table, all I need to do is recompile the dependant code (Oracle also keeps track of the dependencies for you and marks the code as "invalid"
. Oracle makes coding even easier by enabling you to declare in one fell swoop all the variables needed to represent a row in a table. The emprow emp%ROWTYPE command declares a structure emprow that has the same attributes as the columns in the emp table.
---
thanks!!!
recently, ive come across this article comparing oracle's pl/sql and sql server's t-sql:
and i would love if someone could show to implement "anchored declarations".
to quote from the article:
---
To gain an understanding of how PL/SQL can ease your coding, consider the following—unfortunately, common—scenario. Suppose you have a column in a table that is declared as a char (50). In all your stored procedures that reference this column and store values from it in a variable, you also declare your variables to be char (50). Now, after you've finished your umpteenth procedure, you find out that the column needs to be extended to a char (100). In T-SQL, you (or in fact, me during a very long afternoon session several weeks ago) are in for a lot of searching and replacing the char (50) declarations with char (100). But in PL/SQL, you can simply use what's called an anchored declaration and avoid the problem.
An anchored declaration allows you to declare your variable as being of whatever type the particular column in the table is. For example, emp_id emp.empno%TYPE declares a variable called emp_id, which is the same type as the column empno in the emp table. If I change the column type in the table, all I need to do is recompile the dependant code (Oracle also keeps track of the dependencies for you and marks the code as "invalid"
---
thanks!!!