Follow up of my previous article of Remove Duplicate Chars From String here is another great article written by Madhivanan where similar solution is suggested with alternate method of Number table approach. Check out Remove duplicate characters from a string
SQL SERVER - Remove Duplicate Characters From a String
December 30, 2007 by pinaldave
Posted in SQL, SQL Authority, SQL Function, SQL Query, SQL Scripts, SQL Server, SQL Tips and Tricks, T SQL, Technology | 5 Comments
5 Responses to “SQL SERVER - Remove Duplicate Characters From a String”
Leave a Reply
-
About Pinal Dave
Pinalkumar Dave is Microsoft SQL Server MVP and author of over 800 SQL Server articles. He has six years experience as Principal Database Administrator in MS SQL Server 2008/2005, .NET (C#) and ColdFusion MX. He has a Masters of Science degree in Computer Networks, along with MCDBA, MCAD(.NET) and ColdFusion Advanced MX Certifications.
MVP Profile

-
Blog Stats
- 5,737,662 Readers
-
SQLAuthority Links

My Homepage
My Resume
My Other Blog
SQL Server Mag Articles
--------------------
SQLAuthority
Best Articles
Favorite Articles
SQL Script Bank
Top Downloads
--------------------
SQL Interview Q & A
SQL Coding Standards
SQL FAQ Download
--------------------
SQL Random Article
Search SQLAuthority
Subscribe Email Update
SQLAuthority Feed
Translate SQLAuthority
--------------------
Jobs @ SQLAuthority
Find Your IP
Categories
- About Me (41)
- Best Practices (48)
- Data Warehousing (26)
- Database (242)
- DBA (202)
- Main (67)
- MVP (38)
- Pinal Dave (545)
- Software Development (73)
- SQL (826)
- SQL Add-On (77)
- SQL Authority (826)
- SQL Backup and Restore (50)
- SQL Coding Standards (84)
- SQL Constraint and Keys (46)
- SQL Cursor (63)
- SQL Data Storage (19)
- SQL DateTime (35)
- SQL Documentation (293)
- SQL Download (430)
- SQL Error Messages (361)
- SQL Function (96)
- SQL Humor (21)
- SQL Index (68)
- SQL Interview Questions and Answers (63)
- SQL Joins (356)
- SQL Performance (413)
- SQL Puzzle (10)
- SQL Query (826)
- SQL Scripts (530)
- SQL Security (368)
- SQL Server (826)
- SQL Server DBCC (254)
- SQL Stored Procedure (133)
- SQL Tips and Tricks (826)
- SQL Trigger (40)
- SQL User Group (16)
- SQL Utility (62)
- SQLAuthority (17)
- SQLAuthority Author Visit (38)
- SQLAuthority Book Review (29)
- SQLAuthority News (170)
- SQLAuthority Website Review (18)
- T SQL (826)
- Technology (826)
-
Top Posts
- SQL SERVER - Insert Data From One Table to Another Table - INSERT INTO SELECT - SELECT INTO TABLE
- SQL SERVER - Insert Multiple Records Using One Insert Statement - Use of UNION ALL
- SQL SERVER - 2005 - Create Script to Copy Database Schema and All The Objects - Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects
- SQL SERVER - Import CSV File Into SQL Server Using Bulk Insert - Load Comma Delimited File Into SQL Server
- SQL SERVER - Retrieve Current Date Time in SQL Server CURRENT_TIMESTAMP, GETDATE(), {fn NOW()}
- SQL SERVER - Convert Text to Numbers (Integer) - CAST and CONVERT
- SQL Server Interview Questions and Answers Complete List Download
- SQL SERVER - Restore Database Backup using SQL Script (T-SQL)
- SQL SERVER - Shrinking Truncate Log File - Log Full
- SQL SERVER - 2005 List All Tables of Database
- SQL SERVER - 2008 - Interview Questions and Answers Complete List Download
- SQL SERVER - 2005 NorthWind Database or AdventureWorks Database - Samples Databases
-
Recent Posts
- SQL SERVER - Interesting Observation - Using sqlcmd From SSMS Query Editor
- SQL SERVER - sqlcmd vs osql - Basic Comparison
- SQL SERVER - 2008 - Change Color of Status Bar of SSMS Query Editor
- SQL SERVER - Time Delay While Running T-SQL Query - WAITFOR Introduction
- SQL SERVER - 2008 - 2005 - Find Longest Running Query - TSQL
- SQLAuthority News - Happy New Year - 5 SQL New Year Resolutions
- SQLAuthority News - Recap Year 2008 - Two Most Important Event of My Life
- SQLAuthority Author Visit Report - Tech Meetings - Recession - Job Market - Consolidation of Servers - OS Choice - Server Reboots - Performance Optimization - Backup and Restore
- SQL SERVER - 2008 - Certification Path Complete Download PDF
- SQL SERVER - Fix : Msg 15151, Level 16, State 1, Line 3 Cannot drop the login ‘test’, because it does not exist or you do not have permission
- SQL SERVER - Add Any User to SysAdmin Role - Add Users to System Roles
- SQL SERVER - Fix : Error : Msg 15151, Level 16, State 1, Line 2 Cannot alter the login ’sa’, because it does not exist or you do not have permission
- SQLAuthority Author Visit - Valsad, Daman, Silvassa, Vapi - Tech Meetings
- SQLAuthority News - Merry Christmas - Search SQLAuthority
- SQL SERVER - DISABLE and ENABLE user SA
-
Recent Comments
- Vijay Ahire on SQL SERVER - 2005 - Create Script to Copy Database Schema and All The Objects - Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects
- ARUN on Contact Me - Archive 2
- Phani on SQL SERVER - 2005 - Database Table Partitioning Tutorial - How to Horizontal Partition Database Table
- Ghnanambal.K on SQL SERVER - Simple Example of Cursor
- MUKESH BHATT on Contact Me - Archive 1
- sizwe on SQL SERVER - 2005 - Export Data From SQL Server 2005 to Microsoft Excel Datasheet
- HaiMT on Contact Me
- Alex Austin on SQL SERVER - Fix : Error : Msg 7311, Level 16, State 2, Line 1 Cannot obtain the schema rowset DBSCHEMA_TABLES_INFO for OLE DB provider SQLNCLI for linked server LinkedServerName
- John on SQL SERVER - Interesting Observation - Using sqlcmd From SSMS Query Editor
- SQL SERVER - Interesting Observation - Using sqlcmd From SSMS Query Editor Journey to SQL Authority with Pinal Dave on SQL SERVER - sqlcmd vs osql - Basic Comparison
- Rajgopal on SQL SERVER - Guidelines and Coding Standards Part - 2
- miscwicky on SQL SERVER - Roadmap of Microsoft Certifications - SQL Server Certifications
- shilpa on SQL SERVER - 2008 - Interview Questions and Answers - Part 1
- REM on SQL SERVER - 2005 - Create Script to Copy Database Schema and All The Objects - Stored Procedure, Functions, Triggers, Tables, Views, Constraints and All Other Database Objects
- James on SQL SERVER - 2008 - 2005 - Find Longest Running Query - TSQL
Archives
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
-
Pages
-
Latest Articles
-
pinaldave
- SQL SERVER - Interesting Observation - Using sqlcmd From SSMS Query Editor
- SQL SERVER - sqlcmd vs osql - Basic Comparison
- SQL SERVER - 2008 - Change Color of Status Bar of SSMS Query Editor
- SQL SERVER - Time Delay While Running T-SQL Query - WAITFOR Introduction
- SQL SERVER - 2008 - 2005 - Find Longest Running Query - TSQL
- SQLAuthority News - Happy New Year - 5 SQL New Year Resolutions
- SQLAuthority News - Recap Year 2008 - Two Most Important Event of My Life
- SQLAuthority Author Visit Report - Tech Meetings - Recession - Job Market - Consolidation of Servers - OS Choice - Server Reboots - Performance Optimization - Backup and Restore
- SQL SERVER - 2008 - Certification Path Complete Download PDF
- SQL SERVER - Fix : Msg 15151, Level 16, State 1, Line 3 Cannot drop the login ‘test’, because it does not exist or you do not have permission
-
-
Click Cloud
About Me Best Practices Database Data Warehousing DBA Main MVP Pinal Dave Software Development SQL SQL Add-On SQL Authority SQLAuthority SQLAuthority Author Visit SQLAuthority Book Review SQLAuthority News SQLAuthority Website Review SQL Backup and Restore SQL Coding Standards SQL Constraint and Keys SQL Cursor SQL Data Storage SQL DateTime SQL Documentation SQL Download SQL Error Messages SQL Function SQL Humor SQL Index SQL Interview Questions and Answers SQL Joins SQL Performance SQL Puzzle SQL Query SQL Scripts SQL Security SQL Server SQL Server DBCC SQL Stored Procedure SQL Tips and Tricks SQL Trigger SQL User Group SQL Utility Technology T SQL






hi little help here plz,
i have table with the data like below:
ids_cloumn
========================
1 , 2 , 4 , 23 , 12 , 11 , 9 , 8 , 7 , 10 ,
1 , 3 , 4 , 21 , 16 , 12 , 19 , 10 ,
2 , 3 , 6 , 24 , 15 , 18 , 9 , 8 ,
3 , 5 , 8 , 27 , 14 , 19 , 39 , 7 , 13 ,
1 , 7 , 9 , 28 , 19 , 11 , 29 , 8 ,
i am having a list of nos with me (coming from another query)
ex1: 1, 3 & 23
ex2 : 1, 6, 34 & 23
now i want to retrieve the list of rows which is having any of the nos.
is there any other way with out using “LIKE %”
If i am using like i need to write so many OR conditions based on the inputs.
thanks
kris,
You need to split the values return from another query and check againt table column. Search for Split + sql server in google
Also I suggest you to read about normalisation
Hi Madhivanan,
thanks for your reply. the query is returning the values like :
1
3
23
So there is no need to split the values.
Actually i didnt design the database, somebody else did. I was just asked to help regarding this issue.
Right now they are constructing a dinamic query in the program by using LIKE based on the query results and then passing it to SQL SERVER.
many LIKEs in the query is really slowing down the process. So i want to know is there any other way to make it fast.
Kris,
try this
select * from table
where ‘&’+@search_string+’&’ like ‘%&’+cast(col as varchar(10))+’&%’
this is also one type of method
also following transfered like sp or function
declare @i int
declare @c char
declare @rst varchar(8000)
set @i=1
set @rst=substring(’aaassrt’,1,1)
set @c=”
while @i<=len(’aaassrt’)
begin
set @c=substring(’aaassrt’,@i,1)
if charindex( @c,@rst,1)=0
set @rst=@rst+@c
set @i=@i+1
end
select @rst