CrystalDuck
Programmer
I am on SQL Server, rtying to hit an Oracle database, and feel like I'm so close, but it just don't wanna take it....help.
I've converted both dates (PROC_DATE & @previous_date) from SQL and Oracle to strings, hoping that would make it easier, but to no avail. When I hard code a date (ex. 08/04/2005) in the where clause, it pulls cacbk everything just fine, but it is definitely struggling with recognizing that the variable (@previous_date) is also a string, exactly the same format that it's looking for. *ARGH*
When I run the above code, I get two errors, and I just don't get, what the heck??!! I've tried adding and deleting quotemarks, but I feel like I'm just going in circles...any one have any clues?
The errors are:
ANY help is greatly appreciated!
Thanks in advance,
CrystalDuck
![[ponytails2] [ponytails2] [ponytails2]](/data/assets/smilies/ponytails2.gif)
Code:
DECLARE
@previous_date smalldatetime,
@cmd varchar(4000)
--DROP TABLE #OPEN_CLOSE_ALL
Create Table #OPEN_CLOSE_ALL
(PRI_ACCT_ID varchar(14),
SHRHLD_SHORT_NAME varchar(25),
ADDR_LINE1_DESC varchar(50),
CITY_NAME varchar(50),
ST_CODE_SHORT_DESC varchar(25),
POSTAL_CODE varchar(20),
CUSIP_ID varchar(9),
CLASS_NAME varchar(25),
FUND_ID int,
BEG_SHR_BAL_AMT float,
purch_shr_amt float,
rdmp_shr_amt float,
PROC_DATE char(10)
)
IF @Previous_date IS NULL
SET @Previous_date = CONVERT(varchar(12),(dateadd(dd,-1,GETDATE()),101)
SELECT @cmd =
'SELECT * INTO #OPEN_CLOSE_ALL FROM OPENQUERY(PHPROD,
''SELECT DISTINCT
A.PRI_ACCT_ID,
A.SHRHLD_SHORT_NAME,
A.ADDR_LINE1_DESC,
A.CITY_NAME,
D.ST_CODE_SHORT_DESC,
A.POSTAL_CODE,
B.CUSIP_ID,
C.CUSIP_SHORT_NAME,
C.FUND_ID,
E.BEG_SHR_BAL_AMT,
E.purch_shr_amt,
E.rdmp_shr_amt,
TO_CHAR(E.PROC_DATE,''DD/MM/YYYY'')
FROM INST.TB_SHRHLD A
INNER JOIN INST.TB_SHRHLD_CUSIP B
ON A.SHRHLD_ID = B.SHRHLD_ID
INNER JOIN INST.TB_CUSIP C
ON B.CUSIP_ID = C.CUSIP_ID
INNER JOIN INST.TB_ST D
ON A.ST_CODE = D.ST_CODE
INNER JOIN INST.TB_SHRHLD_BAL E
ON (A.SHRHLD_ID = E.SHRHLD_ID
AND B.CUSIP_ID = E.CUSIP_ID)
WHERE c.inst_flag = ''Y''
AND c.subacct_cusip_flag = ''N''
AND TO_CHAR(E.PROC_DATE,''DD/MM/YYYY'') = '''''' + @previous_date + '''''' )'
--select (@cmd)
EXEC (@cmd)
I've converted both dates (PROC_DATE & @previous_date) from SQL and Oracle to strings, hoping that would make it easier, but to no avail. When I hard code a date (ex. 08/04/2005) in the where clause, it pulls cacbk everything just fine, but it is definitely struggling with recognizing that the variable (@previous_date) is also a string, exactly the same format that it's looking for. *ARGH*
When I run the above code, I get two errors, and I just don't get, what the heck??!! I've tried adding and deleting quotemarks, but I feel like I'm just going in circles...any one have any clues?
The errors are:
Code:
Server: Msg 170, Level 15, State 1, Line 15
Line 15: Incorrect syntax near 'DD'.
Server: Msg 105, Level 15, State 1, Line 35
Unclosed quotation mark before the character string '' )'.
ANY help is greatly appreciated!
Thanks in advance,
CrystalDuck
![[ponytails2] [ponytails2] [ponytails2]](/data/assets/smilies/ponytails2.gif)