Solved

Unable To Parse Query

Posted on 2013-02-05
9
249 Views
Last Modified: 2013-02-05
I get the results i'm looking for but still recive this error before it completes
Why?

SELECT     dbo.Segment.ROADJUR, dbo.Segment.L_F_ADD, dbo.Segment.L_T_ADD, dbo.Segment.R_F_ADD, dbo.Segment.R_T_ADD, 
                      dbo.Segment.Geometry,
                      (SELECT LTRIM(RTRIM(UPPER(ISNULL(dbo.Street.Prefix_Full, '')))) + ' ' + 
                          (RTRIM(UPPER(ISNULL(dbo.Street.Street_Name, ''))))   + ' ' + 
                          (RTRIM (UPPER(ISNULL(dbo.Street.Suffix_Cnty, '')))) + '' +
						  (RTRIM (UPPER(ISNULL(dbo.Street.Suffix_Bell, '')))) + ' ' +
						  (RTRIM (UPPER(ISNULL(dbo.Street.Suffix_Direction, ''))))) AS Name,						  
                       (SELECT     Ward_Name
                            FROM          dbo.Ward AS W
                            WHERE      (Ward_ID = dbo.Segment.Left_Mun_ID)) AS L_MUNAME,
                       (SELECT     Ward_Name
                            FROM          dbo.Ward AS W
                            WHERE      (Ward_ID = dbo.Segment.Right_Mun_ID)) AS R_MUNAME, 
					CASE WHEN dbo.Segment.ROADJUR = 'KINGS' THEN 9 WHEN dbo.Segment.ROADJUR = 'CNTY' THEN 15 
					WHEN dbo.Segment.ROADJUR = 'TWP' THEN 16 WHEN dbo.Segment.ROADJUR = 'PRIV' THEN 17 END AS LEVEL
		FROM dbo.Segment INNER JOIN
                      dbo.Ward ON dbo.Segment.Left_Mun_ID = dbo.Ward.Ward_ID AND dbo.Segment.Right_Mun_ID = dbo.Ward.Ward_ID
                     INNER JOIN dbo.Street ON dbo.Segment.Street_ID = dbo.Street.Street_ID

Open in new window

0
Comment
Question by:PtboGiser
[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
  • 5
  • 3
9 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38856585
in the GUI / query designer?
if yes, this comes, I think, from the subqueries and/or CASE statements.
it might also be reserved keywords, for example "level" or "Geometry" might require to be written like [LEVEL] and [Geometry]
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38856592
you might also start using aliases to make your query easier to read:
http://www.experts-exchange.com/Database/Miscellaneous/A_11135-Why-should-I-use-aliases-in-my-queries.html

if the above does not help, try to use a normal query window to run the query.
if that works, it's definitively a limitation of the query designer window.
if there it still does not work, comment out parts of the query until it works, and then you can concentrate on the part that is indeed raising the issue
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 250 total points
ID: 38856602
also try this
SELECT     dbo.Segment.ROADJUR, dbo.Segment.L_F_ADD, dbo.Segment.L_T_ADD, dbo.Segment.R_F_ADD, dbo.Segment.R_T_ADD, 
		dbo.Segment.Geometry,
		(SELECT LTRIM(RTRIM(UPPER(ISNULL(dbo.Street.Prefix_Full, '')))) + ' ' + 
		  (RTRIM(UPPER(ISNULL(dbo.Street.Street_Name, ''))))   + ' ' + 
		  (RTRIM (UPPER(ISNULL(dbo.Street.Suffix_Cnty, '')))) + '' +
		  (RTRIM (UPPER(ISNULL(dbo.Street.Suffix_Bell, '')))) + ' ' +
		  (RTRIM (UPPER(ISNULL(dbo.Street.Suffix_Direction, ''))))) AS Name,						  
		 w1.Ward_Name AS L_MUNAME,
		 w2.Ward_Name AS R_MUNAME, 
		CASE WHEN dbo.Segment.ROADJUR = 'KINGS' THEN 9 WHEN dbo.Segment.ROADJUR = 'CNTY' THEN 15 
WHEN dbo.Segment.ROADJUR = 'TWP' THEN 16 WHEN dbo.Segment.ROADJUR = 'PRIV' THEN 17 END AS [LEVEL]
FROM dbo.Segment 
LEFT JOIN dbo.Ward w1 ON  dbo.Segment.Left_Mun_ID = w1.Ward_ID 
LEFT JOIN dbo.ward w1 ON dbo.Segment.Right_Mun_ID = w2.Ward_ID 
INNER JOIN dbo.Street ON dbo.Segment.Street_ID = dbo.Street.Street_ID

Open in new window

0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 

Author Comment

by:PtboGiser
ID: 38856608
Does not like the word Level
Thanks again
0
 
LVL 143

Assisted Solution

by:Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3] earned 250 total points
ID: 38856618
then use .[Level], and it should work
0
 

Author Closing Comment

by:PtboGiser
ID: 38856642
A Wealth of knowledge as usual
Thanks guys

Is there a Huge advantage in using the
LEFT JOIN dbo.Ward w1 ON  dbo.Segment.Left_Mun_ID = w1.Ward_ID
LEFT JOIN dbo.ward w1 ON dbo.Segment.Right_Mun_ID = w2.Ward_ID

Compared to
Inner Join  dbo.Ward ON dbo.Segment.Left_Mun_ID = dbo.Ward.Ward_ID AND dbo.Segment.Right_Mun_ID = dbo.Ward.Ward_ID

Thanks
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38856675
the 2 joins will make sure it will work, with 1 single join to "ward" you won't get any results UNLESS left_Mun_ID = Right_Mun_ID
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38856678
thanks for the points :)
this one hence pushes me across the 38M points barrier  :)
0
 

Author Comment

by:PtboGiser
ID: 38856704
thanks i will be sure to continue to use the joins that way,
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
find SQL job run average duration 24 57
SQL Query Task 11 43
Linked Server - SP with Param to VIew 7 22
SQL Instance service gone? 5 38
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

749 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