March 11, 2005 at 6:37 am
Hi,
I have a problem which has me stumped. My database has tables which contain (among other things)
products - We sell under three brands, I have three columns to cater for this.
People - A person has an email address and can be linked via a linking table to any of the products they have chosen.
Product Files - Driver files (Urls, date updated etc) are linked via a link table to the products table.
I am developing an e-mail system so a user will receive an e-mail at the end of the week if any of their chosen products has had a file updated in the previous week. All is good so far.
To send the email I use a Stored Procedure to open a cursor with the email addresses of all people associated with products that have had an updated driver.
I then run through this recordset (Fetch) and return the product name and file details for each updated file (multiple products, multiple files per product, I want to tell them which were updated, out of the kindness of my heart).
So, when it comes to opening the second cursor (which I run through, add the data to a variable and send off to my e-mailing Stored Procedure) I need to make sure I get their product's brand name right.
I currently use:-
Declare DetailCursor Cursor For (Select @brd As 'Model', Version, From UserVw_Modified_Files Where Userid='' +@UId+'')
Where @Brd is the brand name (Brand "One", Brand "Two" or Brand "Three"). Unforthunately, it returns the brand name "One", "Two" or "Three" and not the model name of that brand.
I have tried to use
Declare DetailCursor Cursor For (Select Parsename(@brd,1) As 'Model'...... Blah de blah)
But this does exactly the same.
So, after all this typing, does anyone know how I can use a variable name in a select statement and get it to return the column data as opposed to just returning the variable value.
Many Thans in advance
Conway
March 11, 2005 at 7:25 am
Never Mind,
I found a workaround. It would still be good to hear if anyone has a more graceful solution, but this one works.
If(@brd = 'One')
Begin
Declare DetailCursor Cursor For (Select One As 'Model' Etc Etc
End
If(@brd = 'Two')
Begin
Declare DetailCursor Cursor For (Select Two As 'Model' Etc Etc
End
If(@brd = 'Three')
Begin
Declare DetailCursor Cursor For (Select Three As 'Model' Etc Etc
End
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply