Solved

SQL 2005 error in SQL Query

Posted on 2011-03-15
1
283 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 500 total points
ID: 35138989
Hi,
you need to remove the END statement before SET NOCOUNT OFF

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now