Solved

sql query help

Posted on 2014-11-13
7
124 Views
Last Modified: 2014-11-14
I have the query where I Need to say id the sore not grater than 10 , but it through an error message

AND EXISTS (
                        SELECT COUNT(1)
                FROM userScore US2 WITH (NOLOCK)
                    INNER JOIN lkup_VARoadSkill VA WITH (NOLOCK) ON US2.VARoadSkillKey = VA.VARoadSkillKey
                WHERE U.userKey = US2.userKey
                    AND SU.sessionUnitKey = US2.sessionUnitKey
                   
                    AND VA.VARoadSkillAddGradeIn = 1
                    AND US2.userScoreValue = '1'
                  )  > 10
0
Comment
Question by:erikTsomik
[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
7 Comments
 
LVL 11

Expert Comment

by:AkisC
ID: 40440642
Try deleting the word EXISTS

AND  (
                        SELECT COUNT(1)
                FROM userScore US2 WITH (NOLOCK)
                    INNER JOIN lkup_VARoadSkill VA WITH (NOLOCK) ON US2.VARoadSkillKey = VA.VARoadSkillKey
                WHERE U.userKey = US2.userKey
                    AND SU.sessionUnitKey = US2.sessionUnitKey
                   
                    AND VA.VARoadSkillAddGradeIn = 1
                    AND US2.userScoreValue = '1'
                  )  > 10
0
 
LVL 11

Expert Comment

by:AkisC
ID: 40440644
if the above does not work
ALSO replace  COUNT(1) with  COUNT(*)
0
 
LVL 5

Accepted Solution

by:
TONY TAYLOR earned 500 total points
ID: 40440647
Try this...

AND EXISTS (
                        SELECT COUNT(1)
                FROM userScore US2 WITH (NOLOCK)
                    INNER JOIN lkup_VARoadSkill VA WITH (NOLOCK) ON US2.VARoadSkillKey = VA.VARoadSkillKey
                WHERE U.userKey = US2.userKey
                    AND SU.sessionUnitKey = US2.sessionUnitKey
                   
                    AND VA.VARoadSkillAddGradeIn = 1
                    AND US2.userScoreValue = '1'
                HAVING COUNT(1) > 10
                  )  

Open in new window

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 11

Expert Comment

by:AkisC
ID: 40440649
A great tool for writing Sql is SqlPromt, but its not free

http://www.red-gate.com/products/sql-development/sql-prompt/
0
 
LVL 23

Expert Comment

by:Racim BOUDJAKDJI
ID: 40441104
Please recheck the following JOIN conditions

U.userKey = US2.userKey
SU.sessionUnitKey = US2.sessionUnitKey

since neither U nor SU is specified as an alias anywhere in the subquery.
0
 
LVL 49

Expert Comment

by:Vitor Montalvão
ID: 40442069
If you are using the keyword EXISTS you can't compare the result with a value.
If you want to check for a collection of records that has more than 10 entries then TONY TAYLOR provided the correct solution, otherwise reformulate your question and post entire query.
0
 
LVL 23

Expert Comment

by:Racim BOUDJAKDJI
ID: 40442110
@erikTsomik,

I fully agree with Vitor.

It seems that you are not familiar enough with JOIN and EXISTS operators and syntax.  Please reformulate  the question because we do not have enough elements to help you.

Hope this helps.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

726 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