Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Have a function
SQL
SELECT DISTINCT keyid, field1, field2
FROM fnFunction('PARAMETER')

returns
SQL
1           DATA1         DATA2
1           DATA2         DATA3
2           DATA1         DATA3

what i want is remove the duplicate
remove this
SQL
1           DATA1         DATA2

or this, either the two
SQL
1           DATA2         DATA3

as long as the keyid has no duplicate

removing the 2 fields will solve the problem but query must return those 2 value in my application(vb.net)
Posted
Updated 10-Apr-14 1:01am
v2

Hi,

If you're using SQL Server 2005 or greater, then this should work:
SQL
SELECT  keyid, field1, field2
FROM    (SELECT keyid, field1, field2,
                ROW_NUMBER() OVER (PARTITION BY keyid ORDER BY field1, field2) AS RowNumber
         FROM fnFunction('PARAMETER')
         ) AS sub
WHERE   sub.RowNumber = 1;

I am assuming that fnFunction is a table-valued function.
 
Share this answer
 
Comments
hansoctantan 10-Apr-14 7:45am    
thanks, it works
Andrius Leonavicius 10-Apr-14 7:47am    
You're welcome. Thank you.
I'm not sure about the keyid field, but for the others you can use a UNION

Select field1 from fn('PARAMETER')
 UNION
Select field2 from fn('PARAMETER')

If you add the keyid field then you'll get (in general) more records, You may wish to dump this into a temp table and process that with a second query - this depending upon what is in the keyid field.

A view (instead of temp table) may be a better choice, depending upon how you use the data.


 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900