Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help with this Query

Author  Topic 

wisdomtree2009
Starting Member

5 Posts

Posted - 2009-01-09 : 01:38:07
Hi I have written a Query to test a report which displays data from different tables. As the data is not loaded in the tables yet I have just written the query and sent to my onsite coordinator to verify and he has made a sea change to the query. I could not understand if what i have written is wrong . Please review both the queries and tell me what the difference in both and if there any any advantages/ drawback in either of the approaches

below is the query

what i wrote is this

SELECT S1.Division Manager, SUM (S2.Claims Selected)
FROM
(
SELECT T1.First Name||’ ‘||T1.Last Name AS ‘Division Manager’, T2.INT_CLM_RNSP_CNT
FROM
<ASSOCIATE REGISTER.<DBO>.<TABLE NAME> T1
INNER JOIN
ORT.RU99.RNSP_SRVY T2
ON
<T1.KEY COLUMN=T2.KEY COLUMN>
INNER JOIN
ORT.RU99.RNSP_SRVY_MGR T3
ON
T3.SRVY_ID=T2.SRVY_ID
WHERE
T3.ROLE_CD=1
AND
T2.LOS_DT BETWEEN ?Start Date? And ?End Date?
) S1
GROUP BY S1. Division manager

**************************
CHANGES BY ONSITE COORDINATOR

SELECT T3.LAST_NM || ' ' ||T3. FIRST_NM AS ‘Division Manager’, T4.CLM_SLCTD
FROM
<ASSOCIATE REGISTER SCHEMA NAME.TABLE NAME> T3,
(
SELECT T1.ASSOC_ID, SUM(T2.RNSP_CLM_ID_CNT) CLM_SLCTD
FROM
<ORT SCHEMA NAME>.RNSP_SRVY_MGR T1,
<ORT SCHEMA NAME>.RNSP_SRVY T2
WHERE
T1.SRVY_ID = T2.SRVY_ID
AND
T1.ROLE_CD = 1 AND
T2.LOS_DT >= ?Start Date? AND T2.LOS_DT<= ?End Date?
GROUP BY ASSOC_ID
) T4
WHERE T3.ASSOC_ID = T4.ASSOC_ID

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-09 : 01:43:17
the results will differ provided you've more than one records with same First Name & Last Name but with different ASSOC_ID


also is this sql server? i dont this it is seeing syntax
Go to Top of Page

wisdomtree2009
Starting Member

5 Posts

Posted - 2009-01-09 : 01:47:33
Hi Visakh
This is not SQL server. This is DB2
i dont know where to post this and hence I have posted.

P.S Visakh can i get some guidence from you as to where should i begin learning SQL Server as i am a new bie. Please help me with some approach
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-09 : 01:53:28
quote:
Originally posted by wisdomtree2009

Hi Visakh
This is not SQL server. This is DB2
i dont know where to post this and hence I have posted.

P.S Visakh can i get some guidence from you as to where should i begin learning SQL Server as i am a new bie. Please help me with some approach


try your luck at www.dbforums.com which has db2 forum
start with www.w3schools.com
or

http://searchsqlserver.techtarget.com/generic/0,295582,sid87_gci1057317,00.html
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2009-01-09 : 05:27:17
Hi wisdomtree2009,

Is there some reason you can't (politely) ask your coordinator to explain why he has changed your query? I'm sure he/she would be more than happy to explain their changes and the perceived benefits.


Visakh posted a link to www.w3schools.com which is a good place to start. Like most things you'll get much better by doing.

All the best,


Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -