Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

SQL 2005 error in SQL Query

Posted on 2011-03-15
1
Medium Priority
?
293 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …

783 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