Home > Ask the SQL Server Experts > Tony Bain Questions & Answers > Oracle SQL doesn't work in SQL Server
Ask The SQL Server Expert: Questions & Answers
EMAIL THIS

Oracle SQL doesn't work in SQL Server

Tony Bain EXPERT RESPONSE FROM: Tony Bain

Pose a Question
Other SQL Server Categories
Meet all SQL Server Experts
Become an Expert for this site


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


>
QUESTION POSED ON: 28 October 2003
This SQL works in Oracle, but not in SQL Server. How do I structure it in SQL Server? It determines the number of unique rows (distinct) based on multiple columns.
 
 select count(*)
 FROM
 (select distinct  hdr_invoice_number, trn_sequence, 
 lip_charge_transaction
   from STG1_INVOICE_FACT)

>

The syntax you have supplied does work with SQL Server when you alias the sub select. For example execute the following T-SQL:

create table #demo1
(
 col1 int,
 col2 int,
 col3 int
)
insert #demo1 values(1,2,3)
insert #demo1 values(1,2,3)
insert #demo1 values(1,2,4)
insert #demo1 values(1,2,4)
insert #demo1 values(1,2,4)
insert #demo1 values(5,6,7)
insert #demo1 values(6,7,8)

select count(*)
from( select distinct col1, col2, col3
 from #demo1) table1
This produces a COUNT(*) of 4 which is the number of distinct rows when selecting unqiness based on the three columns. Similarly this code:
select count(*)
from( select distinct col1, col2 
 from #demo1) table1
produces a count(*) of 3 as uniqueness is being selected on only two columns.

For More Information


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
Tony Bain
Application not resolving username and password
Problems trying to install SQL Server on a two-node cluster on SAN
Error connecting to Web-based application
Conversion of char datatype to datetime datatype resulted in an out of range datetime value
Getting error when dropping, inserting into or truncating table with QA
Often used SP wiped out the database
Tony's SQL Server book for DBAs
Finding gaps in column of sequential numbers
Exporting T-SQL scripts from command line
Recovering the database from the MDF file

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



SQL Solutions - SQL Database Design
HomeNewsTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2005 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts