Click here to Skip to main content
15,891,703 members
Home / Discussions / Database
   

Database

 
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 
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 
Trustapple wrote:
Thanks


You're welcome.

Trustapple wrote:
along with our query i want it to also do this that is if the customername is Mika (ie the name is only one word and it doesnot contain any ',' or ' ')Then it should update to FirstName.....


Do you mean something like this:
update TableName
set lastname 
    = 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
            TableName.LastName --<code> no delimitter so don't change lastname in the table</code>
      end,
   firstname 
   = 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
           customername -- <code>no delimiter so use the full data to firstname</code>
        end ...


The need to optimize rises from a bad design.My articles[^]

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 
GeneralRe: Use a calculated value in multiple places in a query Pin
Ben Fair10-Dec-08 9:17
Ben Fair10-Dec-08 9:17 
GeneralRe: Use a calculated value in multiple places in a query Pin
Wendelius10-Dec-08 9:26
mentorWendelius10-Dec-08 9:26 
GeneralRe: Use a calculated value in multiple places in a query Pin
Ben Fair10-Dec-08 9:41
Ben Fair10-Dec-08 9:41 
GeneralRe: Use a calculated value in multiple places in a query Pin
PIEBALDconsult10-Dec-08 15:49
mvePIEBALDconsult10-Dec-08 15:49 
GeneralRe: Use a calculated value in multiple places in a query Pin
Wendelius10-Dec-08 18:16
mentorWendelius10-Dec-08 18:16 

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.