December 25, 2013 at 10:13 pm
For examble:
In a table name like
1.Test
2.Test.
3.Test..
4.Test...
How will get the name "Test" using distinct keyword?
December 26, 2013 at 5:10 am
SELECT DISTINCT Name
FROM dbo.YourTable
;
But, beware... this type of logic is frequently due to bad table or data design and can lead to some mighty slow queries.
--Jeff Moden
Change is inevitable... Change for the better is not.
December 28, 2013 at 5:15 am
Would you mind being a little more specific?
What is the "business logic" to get to the result you're looking for?
It's unknown, whether the value is "2.Test." or "Test.".
It is also unknown, whether you're looking for identical characters at position 3 to 7 (or 1 to 4, respectively), or for the substring "Test", regardless of the position within the string itself.
Please help us help you.
January 1, 2014 at 11:11 pm
Thanks for your response..
I need little more specific..
Business logic is I need to export all values from a table without any duplication. I considered Test. Test.. are the duplicates.
The value is "Test." not "2.Test."
January 2, 2014 at 1:09 am
sql-programmers (1/1/2014)
Thanks for your response..I need little more specific..
Business logic is I need to export all values from a table without any duplication. I considered Test. Test.. are the duplicates.
The value is "Test." not "2.Test."
Then your SELECT DISTINCT will do fine.
--Jeff Moden
Change is inevitable... Change for the better is not.
January 2, 2014 at 1:43 am
I don't think a simple DISTINCT will do it since it would return two rows ("Test." and "Test..") where one ("Test") is expected.
Maybe one of the following approaches will work:
SELECT DISTINCT (LEFT(yourColumn,4)) FROM yourTable
SELECT DISTINCT (REPLACE(yourColumn,'.','')) FROM yourTable
But that's just guessing based on your sample data...
January 2, 2014 at 7:24 am
LutzM (1/2/2014)
I don't think a simple DISTINCT will do it since it would return two rows ("Test." and "Test..") where one ("Test") is expected.Maybe one of the following approaches will work:
SELECT DISTINCT (LEFT(yourColumn,4)) FROM yourTable
SELECT DISTINCT (REPLACE(yourColumn,'.','')) FROM yourTable
But that's just guessing based on your sample data...
Dang... I thought the dots were just noise. This is why I wish people would provide data in a readily consumable format.
Before you make another post, please see the first link under "Helpful Links" in my signature line below. It helps eliminate confusion and increases the likelihood of you actually getting a correct answer to your problem and fairly quickly, too.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply