- Feb 18, 2011
- 2,716
- 4
- 81
I'm not a programmer period. My boss decided to hand this to me.
Basically he wants sql sp to build a sql statement dynamically and output the date. from that statement you get an date output that plugs into another sql statement. I basically google and try to figure this out . Doesn't seem to work. Not sure what to try.
so there is a table sqlrule say
SQLDATE TABLENAME, ID1, ID2, ID3
DATE ; SQLTABLEA ; SOC; FUTURA; DR
SO basically my sql takes the 3 ID and find what to pick and from what table. Basically he would input a bunch of rules , ie SQLDATE will have different ID1-3 so if you use different ID1-3 parameter, you get a different SQLDATE
@SQLV = (Select 'SELECT ' +SQLDATE+ ' FROM ' + TABLENAME FROM SQLRULE where id1 = 'SOC' AND ID2 ='FUTURA', and ID3 = 'DR')
and upon exec (@SQLV)
it'll be 'SELECT DATE FROM SQLTABLEA' which will return ie 10/28/2020 (todays date)
So Im trying to run this in another store procedure but I'm not able to grab the output, I tried to set a @dateout output and use it within another sp and its just returning 1900/1/1 since i'm probably doing it wrong
so my second sp is like
CREATE PROCEDURE SP2 AS
.
.
Run the first date SP @dateout
SELECT 'xxx' as a, 'yyy' as b, 'zzz' as c, @dateout as DATE
Basically I have no idea what i'm doing.. so i'm probably not doing this right. If anyone have a crash course or something I can try .. thanks
Basically he wants sql sp to build a sql statement dynamically and output the date. from that statement you get an date output that plugs into another sql statement. I basically google and try to figure this out . Doesn't seem to work. Not sure what to try.
so there is a table sqlrule say
SQLDATE TABLENAME, ID1, ID2, ID3
DATE ; SQLTABLEA ; SOC; FUTURA; DR
SO basically my sql takes the 3 ID and find what to pick and from what table. Basically he would input a bunch of rules , ie SQLDATE will have different ID1-3 so if you use different ID1-3 parameter, you get a different SQLDATE
@SQLV = (Select 'SELECT ' +SQLDATE+ ' FROM ' + TABLENAME FROM SQLRULE where id1 = 'SOC' AND ID2 ='FUTURA', and ID3 = 'DR')
and upon exec (@SQLV)
it'll be 'SELECT DATE FROM SQLTABLEA' which will return ie 10/28/2020 (todays date)
So Im trying to run this in another store procedure but I'm not able to grab the output, I tried to set a @dateout output and use it within another sp and its just returning 1900/1/1 since i'm probably doing it wrong
so my second sp is like
CREATE PROCEDURE SP2 AS
.
.
Run the first date SP @dateout
SELECT 'xxx' as a, 'yyy' as b, 'zzz' as c, @dateout as DATE
Basically I have no idea what i'm doing.. so i'm probably not doing this right. If anyone have a crash course or something I can try .. thanks
