Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL cross join syntax problem

Posted on 2011-09-12
8
Medium Priority
?
777 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
LVL 5

Accepted Solution

by:
Brian Chan earned 500 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 500 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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

670 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