June 4, 2007 at 3:07 pm
Hello everybody,
i hope somebody can give me a hint: is it possible to declare a variable and use its value as an alias in a select statement afterwards like
DECLARE @test_var varchar(10)
SELECT @test_var = (SELECT [col_1] FROM [table_1] WHERE [col_2]='something')
SELECT [col_1],
FROM [table_2] AS @j...
June 4, 2007 at 3:15 pm
Can't think of why you would want to do that, but if I had a need to do something like that, it really sounds like dynamic sql is the only way to accomplish it.
June 4, 2007 at 3:30 pm
Well, I have a table that contains keys and values: COL_KEY and COL_NAME. The first contains a nutrient code (always the same, no matter the language). The later contains nutrient names in a specific language. Like xyz_cal='Calories' in an English table, and xyz_cal='Kalorien' in a German table. There is another table with items (recipes and components) that have different nutrients and their values assigned (like 'Pancake' has 'xyz_cal'=200...). I'd like to select all the values for a selected item with COL_NAME of a nutrient in the target language. How would you use dynamic sql?
June 4, 2007 at 5:16 pm
Now i need more info. DDL for the tables and some sample data plus expected output based on the sample data.
With that, either I or someone else out there will come up with a way of doing it.
June 4, 2007 at 5:23 pm
SELECT @j-2 AS ParameterName, [col_1] AS parameterValue
FROM [table_2] ...
_____________
Code for TallyGenerator
June 7, 2007 at 12:26 am
Perhaps you want a table variable?
DECLARE @Table TABLE
(
Column1 INT NOT NULL,
Column2 VARCHAR(10) NOT NULL
)
June 7, 2007 at 1:42 am
Or you could define a separate view for each language
David
If it ain't broke, don't fix it...
June 8, 2007 at 1:49 pm
Search this site for "DYNAMIC SQL".
RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply