Solved

SQL cross join syntax problem

Posted on 2011-09-12
8
755 Views
Last Modified: 2012-05-12
select count(*) 'VolumeA' from tableA
cross join
select count(*) 'VolumeB' from tableB

error says "Incorrect syntax near the keyword 'select'"

I simply like the counts to be side by side.

Suggestions?
0
Comment
Question by:simplyfemales
[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
8 Comments
 
LVL 5

Expert Comment

by:Brian Chan
ID: 36527158
instead, try this

select count(*) 'VolumeA' from tableA
cross join
(select count(*) 'VolumeB' from tableB)
0
 
LVL 5

Expert Comment

by:Brian Chan
ID: 36527172
Ooooo.... What am I doing?

It should be:

Select tabA.VolumeA, tabB.VolumeB
(select count(*) 'VolumeA' from tableA) as tabA
cross join
(select count(*) 'VolumeB' from tableB) as tabB
0
 

Author Comment

by:simplyfemales
ID: 36527220
Select tabA.VolumeA, tabB.VolumeB
(select count(*) 'VolumeA' from tableA) as tabA
cross join
(select count(*) 'VolumeB' from tableB) as tabB

doesn't work.

Incorrect syntax near the keyword 'select'
Incorrect syntax near ')'
Incorrect syntax near the keyword 'as'
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 5

Accepted Solution

by:
Brian Chan earned 125 total points
ID: 36527239
My typo..... I missed the FROM

Select tabA.VolumeA, tabB.VolumeB
FROM
(select count(*) 'VolumeA' from tableA) as tabA
cross join
(select count(*) 'VolumeB' from tableB) as tabB
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 36527242
cross join works like this

chabge ID_A and ID_B as per your column names

select count(ID_A) 'VolumeA' , Count(ID_B) 'VolumeB'  from tableA
cross join tableB
0
 
LVL 60

Assisted Solution

by:Kevin Cross
Kevin Cross earned 125 total points
ID: 36527262
An you probably just want something simple like this:

SELECT (SELECT COUNT(1) FROM tableA) AS VolumeA
      , (SELECT COUNT(1) FROM tableB) AS VolumeB
;

Open in new window

0
 
LVL 5

Expert Comment

by:Brian Chan
ID: 36527423
@simplyfemales, seriously if you are not obsessive with using cross join, mwvisa1's solution is much cleaner cut.
0
 

Author Closing Comment

by:simplyfemales
ID: 36530176
Both great suggestions.  Thanks.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Audit has been really one of the more interesting, most useful, yet difficult to maintain topics in the history of SQL Server. In earlier versions of SQL people had very few options for auditing in SQL Server. It typically meant using SQL Trace …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

623 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