April 24, 2023 at 8:06 pm
I would say that you have a trigger on that table that is removing seconds from the column.
and I also assume you are clearing that table in order to do this testing and that the data you show us is not old data!!!
April 24, 2023 at 8:14 pm
Still think it’s part of the insert in the proc as the convert to char needs to be outside of the dynamic SQL, as for why it was giving a syntax issue I don’t know.
Regional settings doing some funky stuff with dates to strings etc.
Can you change the code to set a variable and then set that to be the dynamically built string, then select the string, then execute the string.
Declare @sql nvarchar(max)
Set @sql = 'BULK INSERT #TEMP_TABLE
FROM ''' +
@FILEPATH +
''' WITH (FIRSTROW = 2, FIELDTERMINATOR = '','', ROWTERMINATOR = ''\n'', MAXERRORS = 0);
UPDATE #TEMP_TABLE
SET UNDERLYING_SYMBOL = ''SPX''
WHERE TRIM(UNDERLYING_SYMBOL) LIKE ''^SPX''
INSERT INTO DBO.OptionsEOD
SELECT *, ''' + convert(varchar(26),@RECORD_ADD_DATE, 121) + ''' AS TIME_STAMP
FROM #TEMP_TABLE'
Select @sql
Exec (@sql)
What does the select show, both with and without the convert?
April 24, 2023 at 8:16 pm
I would say that you have a trigger on that table that is removing seconds from the column.
and I also assume you are clearing that table in order to do this testing and that the data you show us is not old data!!!
there are no db triggers. i just checked.
yes I am truncating the table each time I am testing.
Or where you do this
DECLARE @RECORD_ADD_DT datetime
SET @RECORD_ADD_DT = @RECORD_ADD_DATE
do this instead
DECLARE @RECORD_ADD_DT varchar(26)
SET @RECORD_ADD_DT = convert(varchar(26),@RECORD_ADD_DATE,121)
April 24, 2023 at 8:38 pm
Still think it’s part of the insert in the proc as the convert to char needs to be outside of the dynamic SQL, as for why it was giving a syntax issue I don’t know.
Regional settings doing some funky stuff with dates to strings etc.
Can you change the code to set a variable and then set that to be the dynamically built string, then select the string, then execute the string.
Declare @sql nvarchar(max)
Set @sql = 'BULK INSERT #TEMP_TABLE
FROM ''' +
@FILEPATH +
''' WITH (FIRSTROW = 2, FIELDTERMINATOR = '','', ROWTERMINATOR = ''\n'', MAXERRORS = 0);
UPDATE #TEMP_TABLE
SET UNDERLYING_SYMBOL = ''SPX''
WHERE TRIM(UNDERLYING_SYMBOL) LIKE ''^SPX''
INSERT INTO DBO.OptionsEOD
SELECT *, ''' + convert(varchar(26),@RECORD_ADD_DATE, 121) + ''' AS TIME_STAMP
FROM #TEMP_TABLE'
Select @sql
Exec (@sql)What does the select show, both with and without the convert?
i tried this. i ran the ssis package and the table optionsEOD is empty. this means that none of the files from the server got downloaded or imported.
April 24, 2023 at 9:01 pm
Or where you do this
DECLARE @RECORD_ADD_DT datetime
SET @RECORD_ADD_DT = @RECORD_ADD_DATEdo this instead
DECLARE @RECORD_ADD_DT varchar(26)
SET @RECORD_ADD_DT = convert(varchar(26),@RECORD_ADD_DATE,121)
it works now. I am seeing seconds!! thank you to everyone who helped me with this!! you guys are awesome!
the problem was that SS was doing an implicit type casting of some kind that was resulting in loss of precision. this was a great learning opp.
matching:
revised script:
ALTER PROCEDURE [dbo].[UpdateOptionsEOD] (@FILENAME varchar(200), @RECORD_ADD_DATE datetime)
AS
DECLARE @FILEPATH VARCHAR(200)
SET @FILEPATH = @FILENAME
--DECLARE @RECORD_ADD_DT datetime
--SET @RECORD_ADD_DT = @RECORD_ADD_DATE
DECLARE @RECORD_ADD_DT varchar(26)
SET @RECORD_ADD_DT = convert(varchar(26),@RECORD_ADD_DATE,121)
DROP TABLE IF EXISTS #TEMP_TABLE;
CREATE TABLE #TEMP_TABLE
(
[UNDERLYING_SYMBOL] [nvarchar](10) NOT NULL,
[QUOTE_DATE] [date] NOT NULL,
more fields
);
Exec ( 'BULK INSERT #TEMP_TABLE
FROM ''' +
@FILEPATH +
''' WITH (FIRSTROW = 2, FIELDTERMINATOR = '','', ROWTERMINATOR = ''\n'', MAXERRORS = 0);
UPDATE #TEMP_TABLE
SET UNDERLYING_SYMBOL = ''SPX''
WHERE TRIM(UNDERLYING_SYMBOL) LIKE ''^SPX''
INSERT INTO DBO.OptionsEOD
SELECT *, ''' + @RECORD_ADD_DT + ''' AS TIME_STAMP
FROM #TEMP_TABLE'
)
DROP TABLE #TEMP_TABLE
Viewing 6 posts - 16 through 20 (of 20 total)
You must be logged in to reply to this topic. Login to reply