SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 print data btween two brackets
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

amurark
Yak Posting Veteran

India
50 Posts

Posted - 04/05/2012 :  00:47:47  Show Profile  Reply with Quote
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

India
48076 Posts

Posted - 04/05/2012 :  01:18:08  Show Profile  Reply with Quote
make use of substring and charindex functions

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

Go to Top of Page

sql-programmers
Posting Yak Master

USA
189 Posts

Posted - 04/05/2012 :  02:01:34  Show Profile  Reply with Quote
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

India
48076 Posts

Posted - 04/05/2012 :  10:25:42  Show Profile  Reply with Quote
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

India
50 Posts

Posted - 04/08/2012 :  23:30:00  Show Profile  Reply with Quote
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

India
48076 Posts

Posted - 04/08/2012 :  23:34:27  Show Profile  Reply with Quote
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

India
50 Posts

Posted - 04/08/2012 :  23:35:43  Show Profile  Reply with Quote
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

India
48076 Posts

Posted - 04/09/2012 :  00:30:50  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000