David Megnin
asked on
Regular Expression to modify a T-SQL query to return formatted dates. (Search and Replace REGEX)
I need a Regular Expression to reconstruct a T-SQL query with a bunch of date columns.
With query items like this:
,[ObtainedGADataSheet]
,[C_ObtainedGADataSheet]
,[ReceivedJobDesc]
,[C_ReceivedJobDesc]
The result should look like this:
,CONVERT(Varchar,[Obtained GADataShee t],101) AS 'ObtainedGADataSheet'
,CONVERT(Varchar,[C_Obtain edGADataSh eet],101) AS 'C_ObtainedGADataSheet'
,CONVERT(Varchar,[Received JobDesc],1 01) AS 'ReceivedJobDesc'
,CONVERT(Varchar,[C_Receiv edJobDesc] ,101) AS 'C_ReceivedJobDesc'
The text editor I'm using to accomplish this is called "EditPad Pro 7" by "Just Great Software Co. Ltd." and supports Regex search and replaces.
I'm tried this in the Search: field:
,.*
And this in the Replace: field:
,CONVERT(Varchar,$&,101) AS '\0'
And I get this result:
,CONVERT(Varchar,,[Obtaine dGADataShe et],101) AS ',[ObtainedGADataSheet]'
,CONVERT(Varchar,,[C_Obtai nedGADataS heet],101) AS ',[C_ObtainedGADataSheet]'
,CONVERT(Varchar,,[Receive dJobDesc], 101) AS ',[ReceivedJobDesc]'
,CONVERT(Varchar,,[C_Recei vedJobDesc ],101) AS ',[C_ReceivedJobDesc]'
There are two extra commas in this result. Each extra is before a "[" character. I see where it's coming from, but I don't know how to fix it. Note that the brackets should be removed from the field name after "AS."
Thanks a bunch.
*Oh, I don't want a Python or C# solution, I'll be continuing to use my text editor's search and replace feature.
A reference to it's syntax can be found here, but it's pretty standard:
http://www.regular-expressions.info/replacematch.html
With query items like this:
,[ObtainedGADataSheet]
,[C_ObtainedGADataSheet]
,[ReceivedJobDesc]
,[C_ReceivedJobDesc]
The result should look like this:
,CONVERT(Varchar,[Obtained
,CONVERT(Varchar,[C_Obtain
,CONVERT(Varchar,[Received
,CONVERT(Varchar,[C_Receiv
The text editor I'm using to accomplish this is called "EditPad Pro 7" by "Just Great Software Co. Ltd." and supports Regex search and replaces.
I'm tried this in the Search: field:
,.*
And this in the Replace: field:
,CONVERT(Varchar,$&,101) AS '\0'
And I get this result:
,CONVERT(Varchar,,[Obtaine
,CONVERT(Varchar,,[C_Obtai
,CONVERT(Varchar,,[Receive
,CONVERT(Varchar,,[C_Recei
There are two extra commas in this result. Each extra is before a "[" character. I see where it's coming from, but I don't know how to fix it. Note that the brackets should be removed from the field name after "AS."
Thanks a bunch.
*Oh, I don't want a Python or C# solution, I'll be continuing to use my text editor's search and replace feature.
A reference to it's syntax can be found here, but it's pretty standard:
http://www.regular-expressions.info/replacematch.html
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.