473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

T Sql join query

1
i have a problems in joins. if i run two queries separately it runs fine but if run using joins its creating problem

Expand|Select|Wrap|Line Numbers
  1. SELECT 
  2. Div, Bill,  count(CPT)) as [Count(Paid Claims)],sum(ChgAmt)as [Charges Paid($)],sum(PayAmt)as [Payments($)], SUM(PayAmt) / SUM(ChgAmt) as [PMT/CHG(%)] ,sum(PayAmt)/ convert(int,count(CPT)) as [AVG PMT ($)] FROM dbo.PaymentFile group by   Bill, Div order by  Div asc, Bill asc
and second query is

Expand|Select|Wrap|Line Numbers
  1. SELECT  
  2. Div, Bill,count(CPT) as [Count(Claims)],sum(ChgAmt)as [Charges($)]
  3. FROM dbo.TransactionFile group by   Bill, Div order by  Div asc, Bill asc
and if i join this query like this

Expand|Select|Wrap|Line Numbers
  1. SELECT  
  2. t.Div, t.Bill, (t.CPT)) as [Count(Claims)], sum(t.ChgAmt)as [Charges($)],
  3. p.Div, p.Bill, (p.CPT))as [Count(Paid Claims)],sum(p.ChgAmt)as [Charges Paid($)],
  4. sum(p.PayAmt)as [Payments($)],(p.CPT))/(t.CPT)) as [Claims(Paid %)],
  5. sum(p.PayAmt)/sum(p.ChgAmt)as [PMT/CHG(%)],
  6. sum(p.PayAmt)/count(p.CPT) as [AVG PMT ($)]
  7. FROM dbo.TransactionFileas t,dbo.PaymentFile as p
  8. group by   t.Bill, t.Div,  p.Bill, p.Div
  9. order by  t.Div asc, t.Bill asc

its taking more than an hour to execute and

i was also getting error in conversion failed when converting the varchar value to data type int

bcoz cpt column is varchar but when i run separately no error occurs

please help me out

thanks in advance
Apr 11 '12 #1
1 2203
ck9663
2,878 Expert 2GB
Check your JOIN syntax....

Happy Coding!!!


~~ CK
Apr 13 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Xenophobe | last post by:
I know this isn't a MySQL forum, but my question is related to a PHP project. I have two tables. table1 table2 "table1" contains 2 columns, ID and FirstName:
1
by: Ira | last post by:
I'm on a hosted Linux server and I have an Outer Join query that's returning on one less row than I expect. There are two rows very similar and I expect them both returned. There are similar...
1
by: Omavlana | last post by:
Hi, I need your help to resolve this problem. I have written a right outer join query between 2 indipendent tables as follows. select b.Account_desc, b.Account, a.CSPL_CSPL from...
0
by: Omavlana | last post by:
Hi, I need your help to resolve this problem. I have written a right outer join query between 2 indipendent tables as follows. select b.Account_desc, b.Account, a.CSPL_CSPL from...
4
by: Shahzad | last post by:
dear respected gurus, I would like to knew how to apply append,insert query for a self table where no primary keys issues. i do have problem say there are 5 rows of single record, this is data...
21
by: CSN | last post by:
I have a pretty simple select query that joins a table (p) with 125K rows with another table (pc) with almost one million rows: select p.* from product_categories pc inner join products p on...
1
by: mcyi2mr3 | last post by:
Hi Help! Im stuck on a join query. Im trying to get distinct (the same row returned only once) user_id and forename from a tbl of users (they are always distinct) where user_id in that tbl...
1
by: dikkuuhh | last post by:
At the moment i have this query: SELECT number, COUNT( * ) as count ' . FROM visit ' . RIGHT JOIN visitHit ON ( visitHit.visitId = visit.id ) AND ( type = "link" ) WHERE ( brochureId = 57 )...
1
by: Luke | last post by:
I have 3 tables (table1, table2, table3), all of them contain same columns ( id, code, date1, date2, date3) and I need to get out by 'code' field all records that: 1. are in all 3 tables (this is...
11
by: bravo | last post by:
hi i need to optimize the join query, which joins three tables say table1 ,table2 , table3 each having huge volume of records... the query is as select table1.id,table2.time,table3.Status from...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.