Click here to Skip to main content
15,892,298 members
Home / Discussions / Database
   

Database

 
QuestionSQL case function to check for charindex as '' or ',' Pin
Trustapple10-Dec-08 8:17
Trustapple10-Dec-08 8:17 
AnswerRe: SQL case function to check for charindex as '' or ',' Pin
Wendelius10-Dec-08 8:29
mentorWendelius10-Dec-08 8:29 
GeneralRe: SQL case function to check for charindex as '' or ',' Pin
Trustapple10-Dec-08 8:48
Trustapple10-Dec-08 8:48 
GeneralRe: SQL case function to check for charindex as '' or ',' [modified] Pin
Wendelius10-Dec-08 8:58
mentorWendelius10-Dec-08 8:58 
GeneralRe: SQL case function to check for charindex as '' or ',' Pin
Trustapple10-Dec-08 9:35
Trustapple10-Dec-08 9:35 
GeneralRe: SQL case function to check for charindex as '' or ',' Pin
Wendelius10-Dec-08 9:41
mentorWendelius10-Dec-08 9:41 
GeneralRe: SQL case function to check for charindex as '' or ',' Pin
Trustapple10-Dec-08 18:58
Trustapple10-Dec-08 18:58 
GeneralRe: SQL case function to check for charindex as '' or ',' Pin
Trustapple10-Dec-08 19:00
Trustapple10-Dec-08 19:00 
Hey Mika,

The time now is 7:59 AM for you,i beleive....Happy sleepingSmile | :) .

Thanks again to you and Ben....It worked.I made slight modification in the query though...a very slight one.
The credit goes to you guys ....

Please see the working query and let me know if any tweaking is necessary...becuase i will be cghnaging this select to update query for around 9million records.....Smile | :)




select customername,
-- get the last name
case
when CHARINDEX(',', customername) > 0 then
SUBSTRING(customername, 1, CHARINDEX(',', customername) - 1) -- comma is delimiter

when CHARINDEX(' ', customername) > 0 then
SUBSTRING(customername, CHARINDEX(' ', customername) + 1, LEN(customername) - CHARINDEX(' ', customername) + 1) -- space is delimiter
else
'' -- neither comma nor space found
end as [lastname],
-- get the first name
case
when CHARINDEX(',', customername) > 0 then
SUBSTRING(customername, CHARINDEX(',', customername) + 1, LEN(customername) - CHARINDEX(',', customername) + 1) -- comma is delimiter
when CHARINDEX(' ', customername) > 0 then


SUBSTRING(customername, 1, CHARINDEX(' ', customername) - 1) -- space is delimiter
else
'' -- neither comma nor space found
end AS [firstname]
from TableName
GeneralRe: SQL case function to check for charindex as '' or ',' Pin
Ben Fair10-Dec-08 9:40
Ben Fair10-Dec-08 9:40 
GeneralRe: SQL case function to check for charindex as '' or ',' Pin
Wendelius10-Dec-08 9:52
mentorWendelius10-Dec-08 9:52 
GeneralRe: SQL case function to check for charindex as '' or ',' Pin
Ben Fair10-Dec-08 10:06
Ben Fair10-Dec-08 10:06 
GeneralRe: SQL case function to check for charindex as '' or ',' [modified] Pin
Trustapple10-Dec-08 19:02
Trustapple10-Dec-08 19:02 
GeneralRe: SQL case function to check for charindex as '' or ',' Pin
Wendelius11-Dec-08 4:07
mentorWendelius11-Dec-08 4:07 
GeneralRe: SQL case function to check for charindex as '' or ',' Pin
Trustapple11-Dec-08 18:03
Trustapple11-Dec-08 18:03 
GeneralRe: SQL case function to check for charindex as '' or ',' Pin
Wendelius12-Dec-08 4:19
mentorWendelius12-Dec-08 4:19 
QuestionRight Outer Joins and performance Pin
dl4gbe10-Dec-08 6:38
dl4gbe10-Dec-08 6:38 
GeneralRe: Right Outer Joins and performance Pin
Hesham Amin10-Dec-08 8:09
Hesham Amin10-Dec-08 8:09 
AnswerRe: Right Outer Joins and performance Pin
Jörgen Andersson10-Dec-08 8:35
professionalJörgen Andersson10-Dec-08 8:35 
AnswerRe: Right Outer Joins and performance Pin
Wendelius10-Dec-08 8:54
mentorWendelius10-Dec-08 8:54 
GeneralRe: Right Outer Joins and performance [modified] Pin
dl4gbe10-Dec-08 16:36
dl4gbe10-Dec-08 16:36 
GeneralRe: Right Outer Joins and performance Pin
Wendelius11-Dec-08 5:41
mentorWendelius11-Dec-08 5:41 
QuestionUse a calculated value in multiple places in a query Pin
totig10-Dec-08 5:30
totig10-Dec-08 5:30 
AnswerRe: Use a calculated value in multiple places in a query Pin
Wendelius10-Dec-08 6:33
mentorWendelius10-Dec-08 6:33 
GeneralRe: Use a calculated value in multiple places in a query Pin
totig10-Dec-08 6:35
totig10-Dec-08 6:35 
GeneralRe: Use a calculated value in multiple places in a query Pin
Wendelius10-Dec-08 9:34
mentorWendelius10-Dec-08 9:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.