SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Help with Syntax error


Help with Syntax error

Author
Message
mlwiller2
mlwiller2
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 37
Having some trouble with a syntax error related to the FROM statements on line 65 and 95:

Use PARCS_DB
GO
TRUNCATE TABLE tbl_Utilities_PARCS_LiveValue
TRUNCATE TABLE tbl_Utilities_PARCS_Totals
TRUNCATE TABLE tbl_Utilities_PARCS_YTD
TRUNCATE TABLE tbl_Utilities_CUB_LiveValue
TRUNCATE TABLE tbl_Utilities_CUB_Totals
TRUNCATE TABLE tbl_Utilities_CUB_YTD
TRUNCATE TABLE tbl_Utilities_BLDG1_LiveValue
TRUNCATE TABLE tbl_Utilities_BLDG1_Totals
TRUNCATE TABLE tbl_Utilities_BLDG1_YTD
GO
DECLARE @Year INT;
SET @Year = 2014;

-- CONVERT TO A DATE TO ALLOW A SARGEABLE PREDICATE IN THE WHERE CLAUSE
DECLARE @Date SMALLDATETIME;
SET @Date = CONVERT(SMALLDATETIME, CONVERT(CHAR(4), @Year), 112);

-- GET PF OLDTOTAL VALUES FROM HISTORY.
INSERT INTO PARCS_DB.dbo.tbl_Utilities_PARCS_Totals
(Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)
SELECT
Jan = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 2 THEN value END),
Feb = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 3 THEN value END),
Mar = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 4 THEN value END),
Apr = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 5 THEN value END),
May = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 6 THEN value END),
Jun = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 7 THEN value END),
Jul = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 8 THEN value END),
Aug = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 9 THEN value END),
Sep = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 10 THEN value END),
Oct = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 11 THEN value END),
Nov = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 12 THEN value END),
Dec = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 1 AND DATEPART(YEAR,DateTime) = DATEADD(YEAR, 1, @Date) THEN value END)
FROM runtime.dbo.History
WHERE Tagname IN ('FQI_PA_B_001.OldTotal','FQI_PS_B_001.OldTotal','FQI_CW_B_002.OldTotal','FQI_NCW_B_001.OldTotal','FQI_NCW_B_002.OldTotal')
AND wwVersion = 'Latest'
AND DateTime >= @Date
AND DateTime < DATEADD(YEAR, 1, @Date)
GROUP BY TagName;

-- GET PF LIVE VALUES.
INSERT INTO PARCS_DB.dbo.tbl_Utilities_PARCS_LiveValue
(Value)
SELECT Value
FROM runtime.dbo.v_live
WHERE Tagname IN ('FQI_CW_B_002.Total','FQI_NCW_B_001.Total','FQI_NCW_B_002.Total','FQI_PA_B_001.Total','FQI_PS_B_001.Total')

-- GET CUB OLDTOTAL VALUES FROM HISTORY.
INSERT INTO PARCS_DB.dbo.tbl_Utilities_CUB_Totals
(Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)
SELECT
Jan = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 2 THEN value END),
Feb = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 3 THEN value END),
Mar = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 4 THEN value END),
Apr = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 5 THEN value END),
May = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 6 THEN value END),
Jun = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 7 THEN value END),
Jul = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 8 THEN value END),
Aug = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 9 THEN value END),
Sep = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 10 THEN value END),
Oct = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 11 THEN value END),
Nov = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 12 THEN value END),
Dec = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 1 AND DATEPART(YEAR,DateTime) = DATEADD(YEAR, 1, @Date) THEN value END)
FROM RTPCUBHIST_001.runtime.dbo.History
WHERE Tagname IN ('FQI_DW_A_01.OldTotal','BOA001_STM_TOTAL.OldTotal','BOA002_STM_TOTAL.OldTotal')
AND wwVersion = 'Latest'
AND DateTime >= @Date
AND DateTime < DATEADD(YEAR, 1, @Date)
GROUP BY TagName;

-- GET CUB LIVE VALUES.
INSERT INTO PARCS_DB.dbo.tbl_Utilities_CUB_LiveValue
(Value)
SELECT
FROM RTPCUBHIST_001.runtime.dbo.v_live
WHERE Tagname IN ('BOA001_STM_TOTAL.Total','BOA002_STM_TOTAL.Total','FQI_DW_A_01.Total')

-- GET BLDG1 OLDTOTAL VALUES FROM HISTORY.
INSERT INTO PARCS_DB.dbo.tbl_Utilities_BLDG1_Totals
(Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec)
SELECT
Jan = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 2 THEN value END),
Feb = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 3 THEN value END),
Mar = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 4 THEN value END),
Apr = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 5 THEN value END),
May = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 6 THEN value END),
Jun = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 7 THEN value END),
Jul = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 8 THEN value END),
Aug = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 9 THEN value END),
Sep = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 10 THEN value END),
Oct = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 11 THEN value END),
Nov = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 12 THEN value END),
Dec = MAX(CASE WHEN DATEPART(MONTH, DateTime) = 1 AND DATEPART(YEAR,DateTime) = DATEADD(YEAR, 1, @Date) THEN value END)
FROM RTPBASHIST01.runtime.dbo.History
WHERE Tagname IN ('PROC_AIR_TOTAL.OldTotal','PLNT_STM_TOTAL.OldTotal','DOM_WTR_TOTAL.OldTotal','SAN_SEW_TOTAL.OldTotal')
AND wwVersion = 'Latest'
AND DateTime >= @Date
AND DateTime < DATEADD(YEAR, 1, @Date)
GROUP BY TagName;

-- GET BLDG1 LIVE VALUES
INSERT INTO PARCS_DB.dbo.tbl_Utilities_BLDG1_LiveValue
(Value)
SELECT
FROM RTPBASHIST01.runtime.dbo.v_live
WHERE Tagname IN ('DOM_WTR_TOTAL.Total','PLNT_STM_TOTAL.Total','PROC_AIR_TOTAL.Total','SAN_SEW_TOTAL.Total')




It's essentially the same piece of code 3 times, with the last 2 instances pulling in data from a linked server is the only difference. Everything else is copy/paste. Any help would be appreciated.
Luis Cazares
Luis Cazares
SSCoach
SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

Group: General Forum Members
Points: 16230 Visits: 19059
Post the exact error you're getting.


Luis C.
General Disclaimer:
Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


How to post data/code on a forum to get the best help: Option 1 / Option 2
mlwiller2
mlwiller2
SSC Rookie
SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)SSC Rookie (41 reputation)

Group: General Forum Members
Points: 41 Visits: 37
Msg 156, Level 15, State 1, Line 65
Incorrect syntax near the keyword 'FROM'.
Msg 156, Level 15, State 1, Line 95
Incorrect syntax near the keyword 'FROM'.
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25819 Visits: 17509
You don't specify any columns in your select statements.


INSERT INTO PARCS_DB.dbo.tbl_Utilities_CUB_LiveValue
(Value)
SELECT
FROM RTPCUBHIST_001.runtime.dbo.v_live
WHERE Tagname IN ('BOA001_STM_TOTAL.Total','BOA002_STM_TOTAL.Total','FQI_DW_A_01.Total')



The select portion needs to know what column(s) to use.

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search