Soo.. is there any way in the world to change a variable name within a loop using the number stored in the count variable. Similiar to:
I've tried numerous combinations and nothing is working.Code:SELECT @CNT = 1 WHILE @CNT <= 3 BEGIN -- THE LVL1 VARIABLE NEEDS TO HAVE THE NUMBER 1 CHANGE AS -- THE NUMBER STORED WITHIN @CNT CHANGES SELECT @LVL = LVL1 FROM @FINALSECTION WHERE ROWNUM = @RowCnt SELECT @STR = @STR + (SELECT hierarchy_number FROM DATABASE.dbo.Hierarchy WHERE hierarchy_id = @LVL) SELECT @STR = @STR + (SELECT hierarchy_NAME FROM DATABASE.dbo.Hierarchy WHERE hierarchy_id = @LVL) SELECT @CNT = @CNT + 1 END
I would also like to put a dash between each 'hierarchy_number' and 'hierarchy_name' that i pull. Similiar logic as:
But that gives an 'Incorrect syntax near ' - '. But only for the second hyphen. WTF!!Code:SELECT @STR = @STR + (SELECT hierarchy_number FROM DATABASE.dbo.Hierarchy WHERE hierarchy_id = @LVL) + ' - ' SELECT @STR = @STR (SELECT hierarchy_NAME FROM DATABASE.dbo.Hierarchy WHERE hierarchy_id = @LVL) + ' - '
Last edited by LiLMsNinja; 09-25-2009 at 02:35 PM. Reason: Stupid formatting.
CodeMonkey +15 | CommunicationSkills -34 | ClarityUsingEnglish -55 | Clarity while pointing at the monitor and making vigorous facial expressions, occasional grunts, and mouth clicks +150
haha.. i'm missing a ' + ' in the second @STR... Where i grab the 'hierarchy_name'. Wow..
But, still need to figure out how to increment the variable
CodeMonkey +15 | CommunicationSkills -34 | ClarityUsingEnglish -55 | Clarity while pointing at the monitor and making vigorous facial expressions, occasional grunts, and mouth clicks +150
have you tried seting the veriable name to a veriable and then concantanating cnt on to it than using that veriable in place of the veriable you want to have change in the query?
I don't even know what language that is your using but to illistrate what i mean i will show you in php with mysql.
The above syntex won't run but should give you anidea of what i am talking about.Code:$i=1;
while($i<=5)
{
$newVar = "oldVar" . $i;
$blah = "Select * from $newvar";
$i++;
}
?>
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks