Posts Topics Forums Images
Search videos from message boards Videos Search messages from microblogs Microblogs Search messages from imdb.com Imdb Search messages from yuku.com Yuku Search messages from lefora.com (free forums) Lefora
My account: Login | Sign Up
Loading... 

Thread: how to write querey return the unique CustomerId with the first CustomerName ?

Started 1 month, 2 weeks ago by Member 3018046
hii , i have question and i wont ask this question in form of the example. if we have table named CUSTOMER: CUSTOMER TABLE: CustomerID : Integer (Not a primary Key) CustomerName : TEXT And This is the table ' s data: CustomerId | CustomerName 12 | Jone 25 | Mark 25 | Marc 10 | AJ we note that ...
Site: CodeProject: Discussion Boards. Free source code and programming help  CodeProject: Discussion Boards. Free source code and programming help - site profile
Forum: SQL / ADO / ADO.NET  SQL / ADO / ADO.NET - forum profile
Total authors: 5 authors
Total thread posts: 8 posts
Thread activity: no new posts during last week
Domain info for: codeproject.com

Other posts in this thread:

il_masacratore replied 1 month, 2 weeks ago
Maybe it ins't the best solution but you can use a group by (CustomerId), then you have to choose wich CustomerName is the choosen (min(CustomerName), max(CustomerName...). Sql: > select CustomerId, max(CustomerName) from Customer group by CustomerId.

J4amieC replied 1 month, 2 weeks ago
SELECT @customerId as customerId, ( SELECT TOP 1 customerName FROM Customer WHERE customerId=@customerID ORDER BY customerName) AS customerName Whenever your data looks this bad, its a sure-fire signal to clean your data, and ensure your apps only insert clean data.

Member 3018046 replied 1 month, 2 weeks ago
Ohhh...Yes it is work !! many thanks

Member 3018046 replied 1 month, 2 weeks ago
hii ,sorry what do you mean by sure-fire signal ? yes i agree with you that the data is look bad , but i work on a huge data that which is extracted by the Customers them self so i can not edit any thing. many thanks

Niladri_Biswas replied 1 month, 2 weeks ago
You can even try this declare @tblcustomer table(customerid int,customername varchar(50)) insert into @tblcustomer select 12,'Jone' union all select 25,'Mark' union all select 25,'Marc' union all select 10,'AJ' select x.customerid ,x.customername from ( select ROW_NUMBER() over (partition by customerid order by customerid) as rn ,customerid ,customername from @tblcustomer)...

i.j.russell replied 1 month, 2 weeks ago
How do you know which is the first CustomerName? Is the 'first' name always the correct one?

J4amieC replied 1 month, 2 weeks ago
Member 3018046 wrote: hii ,sorry what do you mean by sure-fire signal It means that it is time to examine why you have 2 customer records with the same Id, but different names.

 

Top contributing authors

Name
Posts
Member 3018046
3
user's latest post:
how to write querey return the...
Published (2009-11-02 05:51:00)
hii ,sorry what do you mean by sure-fire signal ? yes i agree with you that the data is look bad , but i work on a huge data that which is extracted by the Customers them self so i can not edit any thing. many thanks
J4amieC
2
user's latest post:
how to write querey return the...
Published (2009-11-02 12:35:00)
Member 3018046 wrote: hii ,sorry what do you mean by sure-fire signal It means that it is time to examine why you have 2 customer records with the same Id, but different names.
il_masacratore
1
user's latest post:
how to write querey return the...
Published (2009-11-02 01:32:00)
Maybe it ins't the best solution but you can use a group by (CustomerId), then you have to choose wich CustomerName is the choosen (min(CustomerName), max(CustomerName...). Sql: > select CustomerId, max(CustomerName) from Customer group by CustomerId.
Niladri_Biswas
1
user's latest post:
how to write querey return the...
Published (2009-11-02 05:51:00)
You can even try this declare @tblcustomer table(customerid int,customername varchar(50)) insert into @tblcustomer select 12,'Jone' union all select 25,'Mark' union all select 25,'Marc' union all select 10,'AJ' select x.customerid ,x.customername from ( select ROW_NUMBER() over (partition by customerid order by customerid) as rn ,customerid ,customername from @tblcustomer)X(rn,customerid,customername)...
i.j.russell
1
user's latest post:
how to write querey return the...
Published (2009-11-02 06:14:00)
How do you know which is the first CustomerName? Is the 'first' name always the correct one?

Related threads on "CodeProject: Discussion Boards. Free source code and programming help":

Related threads on other sites:

Thread profile page for "how to write querey return the unique CustomerId with the first CustomerName ?" on http://www.codeproject.com. This report page is a snippet summary view from a single thread "how to write querey return the unique CustomerId with the first CustomerName ?", located on the Message Board at http://www.codeproject.com. This thread profile page shows the thread statistics for: Total Authors, Total Thread Posts, and Thread Activity