Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL 2005 error in SQL Query

Posted on 2011-03-15
1
Medium Priority
?
292 Views
Last Modified: 2012-05-11
I am getting the following syntax error and not seeing the root of the issue. Any assistance is appreciated.

Msg 156, Level 15, State 1, Line 28
Incorrect syntax near the keyword 'SET'.
SET NOCOUNT ON

IF NOT EXISTS(SELECT 1 FROM information_schema.TABLES WHERE table_name = 'cusHealthHomesHealthyKidsDiags') 
CREATE TABLE [dbo].[cusHealthHomesHealthyKidsDiags](
		[DiagnosisId][INT] NULL,
		[DiagnosisCode][VARCHAR](10) NULL,
		[CategoryId][VARCHAR](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]


IF NOT EXISTS(SELECT 1 FROM information_schema.TABLES WHERE table_name = 'cusHealthHomesHealthyKidsCategories')
CREATE TABLE [dbo].[cusHealthHomesHealthyKidsCategories](
		[CategoryName][VARCHAR](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
		[CategoryId][VARCHAR](50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL 
) ON [PRIMARY] 

INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'ALLERGY','ALG' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'ALG') 
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'ASTHMA','AST' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'AST') 
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'BITES','BTE' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'BTE')
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'FOREIGN BODY','FOB' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'FOB')
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'INSECT','INS' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'INS')
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'LEAD','LED' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'LED')
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'SKIN','SKN' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'SKN')
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'TINEA','TIN' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'TIN')
INSERT INTO cusHealthHomesHealthyKidsCategories(CategoryName,CategoryId) SELECT 'UPPER RESP','URP' WHERE NOT EXISTS(SELECT 1 FROM cusHealthHomesHealthyKidsCategories WHERE CategoryId = 'URP')
END

SET NOCOUNT OFF 

IF( 1 = 1)
BEGIN
SELECT 
	Code, 
	Description
FROM 
	Diagnosis dx
	LEFT OUTER JOIN cusHealthHomesHealthyKidsDiags HKDX ON dx.DiagnosisId = HKDX.DiagnosisId
	LEFT OUTER JOIN cusHealthHomesHealthyKidsCategories HKCAT ON HKDX.CategoryId = HKCAT.CategoryId
END
ELSE
BEGIN

DECLARE @ASSIGNEDCAT VARCHAR(50)
SET @ASSIGNEDCAT = NULL

DECLARE @STATUS varchar(10)
IF(1=2)
	SET @STATUS = 'New '
ELSE
	SET @STATUS = ' '

SELECT 
	Code, 
	Description,
	Category = @STATUS + NULL
FROM
	Diagnosis
WHERE
	DiagnosisId IN(NULL)
END

Open in new window

0
Comment
Question by:Jeff S
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 9

Accepted Solution

by:
Roman Gherman earned 2000 total points
ID: 35138989
Hi,
you need to remove the END statement before SET NOCOUNT OFF

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question