Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Would like Syntax Error Help

Author  Topic 

viperbyte
Posting Yak Master

132 Posts

Posted - 2012-12-06 : 14:57:11
Hi guys.

Can someone super please take a look at this and tell me how to correct the error. I get a red squigly line on the line mentioned in the script below. I get a message that says "Syntax error near 'wait_time_ms'.

--capture point-in-time
SELECT wait_type, waiting_tasks_count,
wait_time_ms, max_wait_time_ms,
signal_wait_time_ms
INTO #OriginalWaitStatSnapshot
FROM sys.dm_os_wait_stats;

--wait for X amount of time
WAITFOR DELAY '00:00:02';

--Collect again
SELECT wait_type, waiting_tasks_count,
wait_time_ms, max_wait_time_ms,
signal_wait_time_ms
INTO #LatestWaitStatSnapshot
FROM sys.dm_os_wait_stats;

--compare the results
SELECT 1.wait_type,
(1.wait_time_ms - O.wait_time_s) accum_wait_ms --red squigly line under wait_time_ms on this line
FROM #OriginalWaitSnapshot O
INNER JOIN #LatestWaitStatSnapshot 1 ON
O.wait_type = 1.wait_type
WHERE 1.wait_type_ms > O.wait_time_ms
ORDER BY 1.wait_time_ms DESC

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-12-06 : 15:00:12
Did you mean to use lower case L instead of the digit 1 as the table alias? Change to one of these
--compare the results
SELECT [1].wait_type,
([1].wait_time_ms - O.wait_time_s) accum_wait_ms --red squigly line under wait_time_ms on this line
FROM #OriginalWaitSnapshot O
INNER JOIN #LatestWaitStatSnapshot [1] ON
O.wait_type = [1].wait_type
WHERE [1].wait_type_ms > O.wait_time_ms
ORDER BY [1].wait_time_ms DESC


Or,
--compare the results
SELECT x.wait_type,
(x.wait_time_ms - O.wait_time_s) accum_wait_ms --red squigly line under wait_time_ms on this line
FROM #OriginalWaitSnapshot O
INNER JOIN #LatestWaitStatSnapshot x
ON O.wait_type = x.wait_type
WHERE x.wait_type_ms > O.wait_time_ms
ORDER BY
x.wait_time_ms DESC
Go to Top of Page

viperbyte
Posting Yak Master

132 Posts

Posted - 2012-12-06 : 15:09:34
Brackets or letter 'X' worked. Thank you sooo much.
Go to Top of Page
   

- Advertisement -