Author |
Topic |
jalba07
Starting Member
4 Posts |
Posted - 2006-11-14 : 14:28:10
|
I'm guessing this is a linked table issue since there is nothing else out of the ordinary. Running SQL 2000 with all service packs.The select statement below runs fine, returns data in 2 seconds.../#temp and declarations done/========================================SELECT SUM(I.[SAMPLE]) as SAMPLE_SUM, I.SAMPLE_DATE, T.TOPIC_DESCRIPTIONFROM ENS_MV.eNERGYSolveID.dbo.INTERVAL AS I JOIN TOPICS AS T ON (I.TOPIC_ID = T.TOPIC_ID) JOIN SUBMETER AS SM ON (I.DEVICE_ID=SM.DEVICE_ID) JOIN #TEMP AS TE ON SM.SUB_METER_ID = TE.SUBMETER_IDWHERE I.TOPIC_ID = @int_reading_type AND I.SAMPLE_DATE BETWEEN @dt_date_from AND @dt_date_toGROUP BY I.SAMPLE_DATE, T.TOPIC_DESCRIPTIONORDER BY I.SAMPLE_DATE =============================================However when I pop that into a stored procedure, the query doesn't return (I have let it run for upwards of 20 minutes)...below are the contents of the SP=============================================CREATE PROC TEST ( @vch_submeter_id VARCHAR(1000), @dt_date_from DATETIME, @dt_date_to DATETIME, @int_reading_type INT=NULL, @int_interval INT=NULL)ASSET NOCOUNT ONDECLARE @comma_place INTDECLARE @int_submeter_id VARCHAR(50)CREATE TABLE #TEMP(SUBMETER_ID VARCHAR(50))WHILE len(@vch_submeter_id) > 0BEGIN SET @comma_place=patindex('%;%',@vch_submeter_id) SET @int_submeter_id = substring(@vch_submeter_id, 1, @comma_place-1) SET @vch_submeter_id = substring(@vch_submeter_id, @comma_place+1, len(@vch_submeter_id)) INSERT INTO #TEMP(SUBMETER_ID) VALUES(@int_submeter_id)ENDIF @int_interval = 15BEGIN SELECT SUM(I.[SAMPLE]) as SAMPLE_SUM, I.SAMPLE_DATE, T.TOPIC_DESCRIPTION FROM ENS_MV.eNERGYSolveID.dbo.INTERVAL AS I JOIN TOPICS AS T ON (I.TOPIC_ID = T.TOPIC_ID) JOIN SUBMETER AS SM ON (I.DEVICE_ID=SM.DEVICE_ID) JOIN #TEMP AS TE ON SM.SUB_METER_ID = TE.SUBMETER_ID WHERE I.TOPIC_ID = @int_reading_type AND I.SAMPLE_DATE BETWEEN @dt_date_from AND @dt_date_to GROUP BY I.SAMPLE_DATE, T.TOPIC_DESCRIPTION ORDER BY I.SAMPLE_DATEEND =================================================Am I doing something wrong? |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-14 : 14:33:49
|
Start to debug how many records are inserted in #TEMP table.Comment out IF case. Replace with select * from #tempCheck to see that the expected number of records are in the #temp table.Peter LarssonHelsingborg, Sweden |
 |
|
jalba07
Starting Member
4 Posts |
Posted - 2006-11-14 : 14:37:24
|
Thanks for the quick reply. There are 3 records in the temp table, which is what I expect. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-14 : 14:42:14
|
No empty rows or rows with NULL?Which values do @int_reading_type, @dt_date_from and @dt_date_to have?Peter LarssonHelsingborg, Sweden |
 |
|
jalba07
Starting Member
4 Posts |
Posted - 2006-11-14 : 14:46:24
|
Nope, the rows are 3 ids (912,913,914), nothing else.The sp declaration is EXEC TEST '912;913;914;', '1/13/2006', '1/14/2006', 1621, 15I am 100% certain there is data for those values, since it works outside of the SP as a regular select statement. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-14 : 14:50:36
|
Try to comment out every JOINed table. Start only with the FROM table.When that works, add ONE new joined table. Run again.Then you see where things go wrong.Peter LarssonHelsingborg, Sweden |
 |
|
jalba07
Starting Member
4 Posts |
Posted - 2006-11-14 : 15:25:11
|
That excercise got me to the problem. The interval table is about 20+million rows, so I needed to tie the join of the temp table directly to the Interval table. Thanks a bunch for taking the time to help! |
 |
|
kapinak
Starting Member
4 Posts |
Posted - 2007-12-11 : 16:10:36
|
quote: Originally posted by jalba07 That excercise got me to the problem. The interval table is about 20+million rows, so I needed to tie the join of the temp table directly to the Interval table. Thanks a bunch for taking the time to help!
did u ever resolve this? i am having simiar issues. |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-12-11 : 16:20:54
|
Reorganize the FROM and JOIN and start with the table holding least records.Add a hint (FORCE ORDER) at the very end of query. E 12°55'05.25"N 56°04'39.16" |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|