Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 print data btween two brackets

Author  Topic 

amurark
Yak Posting Veteran

55 Posts

Posted - 2012-04-05 : 00:47:47
Hi All,

Please tell me if i want to print only Deepika Katoch from below data in crystal report. How to do it.
Like this data between brackets get changed,.

Thanks in advance.


*** 04/04/12 11:11:19(Deepika Katoch) ***
Kindly do the needful.


Regards
Ankita


Ankita

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-05 : 01:18:08
make use of substring and charindex functions

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sql-programmers
Posting Yak Master

190 Posts

Posted - 2012-04-05 : 02:01:34
Use this in your Query,


SELECT SUBSTRING('04/04/12 11:11:19(Deepika Katoch)' , CHARINDEX( '(', '04/04/12 11:11:19(Deepika Katoch)') + 1, CHARINDEX(')', '04/04/12 11:11:19(Deepika Katoch)') - CHARINDEX('(', '04/04/12 11:11:19(Deepika Katoch)') -1 )

SQL Server Programmers and Consultants
http://www.sql-programmers.com/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-05 : 10:25:42
another way

SELECT REPLACE(STUFF(field,1,CHARINDEX('(',Field),''),')','') FROM table


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

amurark
Yak Posting Veteran

55 Posts

Posted - 2012-04-08 : 23:30:00
Thanks Visakh for your kindl reply

But i am getting an error
Msg 8116, Level 16, State 1, Line 1
Argument data type text is invalid for argument 1 of stuff function.



Ankita
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-08 : 23:34:27
you should have told us this before. STUFF wont work with text datatype. then you've to use substring and charindex functions.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

amurark
Yak Posting Veteran

55 Posts

Posted - 2012-04-08 : 23:35:43
Hi sql programmers,

Thanks alot for your reply. IT woked for me

But right now i want to cahgne the foramt of the field in the below

21/06/10 11:08:39 from to 06/21/10 11:08:39


i want to print it in mm-dd-yyyy format but its not gettting printed.



SELECT SUBSTRING(Comments , CHARINDEX( '***', comments) + 3,
CHARINDEX('(', comments) - CHARINDEX('***',
comments) -3),CONVERT(VARCHAR(25),SUBSTRING(Comments , CHARINDEX( '***', comments) + 3,
CHARINDEX('(', comments) - CHARINDEX('***',
comments) -3),101) as [mm/dd/yyyy] ,comments,
SUBSTRING(Comments , CHARINDEX( '(', comments) + 1, CHARINDEX(')', comments) - CHARINDEX('(',
comments) -1 ) as Resolved_By ,
* from OCMQM1




Ankita
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-09 : 00:30:50
why should you do it in sql? why cant you return it as datetime and do formatting at front end?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -