Re: MS SQL dealing with duplicate columns in rows?




Hello,

Suppose I have the following table...

name employeeId email
--------------------------------------------
Tom 12345 t...@xxxxxxxxxxxxx
Hary 54321
Hary 54321 h...@xxxxxxxxxxxxx

I only want unique employeeIds return. If I use Distinct it will
still
return all of the above as the email is different/missing. Is there a
way to query in SQL so that only distinct employeeId is returned? no
duplicates.

I wouuld like to say WHERE no blank fields are present to get the
right row to return.

Many thanks

Yas

Which row for Hary do you want to be returned? The one without an
email address or the one with the email address?

basically 1 that doesn't have any fields missing....

cheers


SELECT * from table where name<>"" and employeeId<>0 and email<>"";

Just a note:

Please, no double quotes for string constants, use single quotes.

Double quotes are reserved for "delimited identifiers" as defined by the
SQL Standard and supported by MS SQL Server.


--
Martijn Tonies
Database Workbench - tool for InterBase, Firebird, MySQL, NexusDB, Oracle &
MS SQL Server
Upscene Productions
http://www.upscene.com
My thoughts:
http://blog.upscene.com/martijn/
Database development questions? Check the forum!
http://www.databasedevelopmentforum.com


.



Relevant Pages

  • Bad data
    ... I am creating a DTS process that will extract data from a ... text file and place it into sql server. ... double quotes must be off, because when I try to tell sql ...
    (microsoft.public.sqlserver.dts)
  • Re: using VBA to insert records from access database to sql server
    ... In SQL you 'escape' single quotes by doubling them. ... > Dim oConn As ADODB.Connection ... > Dim strInsert As String ...
    (microsoft.public.access.modulesdaovba)
  • Re: using VBA to insert records from access database to sql server
    ... "Brendan Reynolds" wrote: ... > In SQL you 'escape' single quotes by doubling them. ... >> Dim oConn As ADODB.Connection ...
    (microsoft.public.access.modulesdaovba)
  • SQL CONTAINS clause parameter substitution problem
    ... I'm in the process of parameterising the SQL SELECT statements in my ... result from parameters within quotes not being substitued. ... single and multiple search strings: ... My problems began when I modified the code to use an SqlCommand ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: sql injection and php
    ... Some developers have seen samples on illegal login using "' --" (quote ... rid of those dashes (SQL comments). ... SQL Server), the quotes only have a special meaning inside a string ...
    (Vuln-Dev)