Solved

SQL 2005 error in SQL Query

Posted on 2011-03-15
1
284 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

863 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

27 Experts available now in Live!

Get 1:1 Help Now