Reg : charindex & substring in sql server 2005

Last Post 13 Jun 2011 07:18 AM by vinoth. 4 Replies.
AddThis - Bookmarking and Sharing Button Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
vinoth
New Member
New Member

--
11 Jun 2011 06:14 AM
For example:
 i am having 123-45-6789

I need to find the both position "-"
output like : 4,7

Have to use charindex & substring.
Query needed , any one help..

Regards
Vinoth
gunneyk
New Member
New Member

--
12 Jun 2011 01:26 PM
Try this:

DECLARE @X VARCHAR(11) ;
SET @x = '123-45-6789' ;

SELECT CHARINDEX('-',@x,1),CHARINDEX('-',@x,CHARINDEX('-',@x,1)+1) ;

vinoth
New Member
New Member

--
12 Jun 2011 07:29 PM
Hi Gunney

Any how thanks for sending.
I need to get the output in single column , not in two separate column.
I need the out[ut : 4,7
Will it possible , let me know.

Regards
Vino
gunneyk
New Member
New Member

--
13 Jun 2011 05:48 AM
In what form? To put them both in a single column of a result set you need to concatentate them which means a string. What do you plan to do with the result? In any case you can format it how ever you like.

DECLARE @X VARCHAR(11) ;
SET @x = '123-45-6789' ;

SELECT CAST(CHARINDEX('-',@x,1) AS VARCHAR(2)) + ',' + CAST(CHARINDEX('-',@x,CHARINDEX('-',@x,1)+1) AS VARCHAR(2));

vinoth
New Member
New Member

--
13 Jun 2011 07:18 AM
Hi Gunneyk

Thank for sending the Query.
I am looking fwd to study SSIS & SSRS .
If u have any video tutorial and any pdf doc . just send the link.
Currently i am looking for sql server job , in chennai , India
If u know any openings , let me know.


Regards
Vino
You are not authorized to post a reply.

Acceptable Use Policy