123
votes
14answers
219k views

Split string in SQL

Using SQL Server 2005, how do I split a string so I can access item x? For example, take the string "Hello John Smith". How can I split the string by a space and access the item at index 1 which ...
62
votes
4answers
70k views

IndexOf function in t-Sql

Given an email address column, I need to find the position of the @ sign for substringing. What is the indexof function, for strings in t-sql. Looking for something that returns the position of a ...
60
votes
4answers
40k views

How to use GROUP BY to concatenate strings in MySQL?

Basically the question is how to get from this: id string 1 A 1 B 2 C to this: id string 1 A B 2 C
36
votes
13answers
18k views

Strings as Primary Keys in SQL Database

I am not very familiar with databases and the theories behind how they work. Is it any slower from a performance standpoint (inserting/updating/querying) to use Strings for Primary Keys than ...
34
votes
3answers
15k views

String concatenation does not work in SQLite

I am trying to execute a SQlite replace function, but use another field in the function. select locationname + '<p>' from location; In this snip, the result is a list of 0s. I would have ...
32
votes
12answers
25k views

Cleanest way to build an SQL string in Java

I want to build an SQL string to do database manipulation (updates, deletes, inserts, selects, that sort of thing) - instead of the awful string concat method using millions of "+"'s and quotes which ...
30
votes
22answers
30k views

The most sophisticated way for creating comma-separated Strings from a Collection/Array/List?

During my work with databases I noticed that I write query strings and in this strings I have to put several restrictions in the where-clause from a list/array/collection. Should look like this: ...
30
votes
4answers
33k views

Best way to strip html tags from a string in sql server?

I've got data in SQL Server 2005 that contains html tags and I'd like to strip all that out, leaving just the text between the tags. Ideally also replacing things like &lt; with <, etc. Is ...
22
votes
4answers
27k views

How to count instances of character in SQL Column

I have an sql column that is a string of 100 'Y' or 'N' characters. For example: YYNYNYYNNNYYNY... What is the easiest way to get the count of all 'Y' symbols in each row.
21
votes
2answers
11k views

How to find similar results and sort by similarity?

How do I query for records ordered by similarity? Eg. searching for "Stock Overflow" would return Stack Overflow SharePoint Overflow Math Overflow Politic Overflow VFX Overflow Eg. searching for ...
21
votes
4answers
18k views

SQL SUBSTRING vs RIGHT - Best Practice

I'm trying to find out the best practice when removing characters from the start of a string. In some languages, you can use MID without a length parameter however, in TSQL the length is required. ...
16
votes
4answers
12k views

Better techniques for trimming leading zeros in SQL Server?

I've been using this for some time: SUBSTRING(str_col, PATINDEX('%[^0]%', str_col), LEN(str_col)) However recently, I've found a problem with columns with all "0" characters like '00000000' because ...
15
votes
2answers
14k views

How can you find the number of occurrences of a particular character in a string using sql?

How can you find the number of occurrences of a particular character in a string using sql? Example: I want to find the number of times the letter ‘d’ appears in this string. declare @string ...
13
votes
5answers
10k views

SQL: search for a string in every varchar column in a database

I have a database where a misspelled string appears in various places in different tables. Is there a SQL query that I can use to search for this string in every possible varchar/text column in the ...
1
vote
3answers
50 views

get first letter of string, disregarding “the”

I am trying to get a list of book titles that begin with a certain letter. However, I need to disregard "the" at the beginning of the title. For instance, when I'm looking for titles that begin with ...

1 2 3 4 5 36
15 30 50 per page