Extract date from text string - Transact-SQL
Hello,
I have a field in my database with an archived date... (Giampaoli Live Oak, Almonds Archive 09/16/10)
I need to be able to extract the date from this, then perform a datepart function on it... How do I extract the date into it's own value using just SQL?
Thanks,
Wes
Thanks Guys,
This helped me:
select
ID,
NAME,
datepart(month, CONVERT(date, SUBSTRING(YOUR_COLUMN_NAME, patindex('%[0-9][0-9]/[0-9][0-9]/[0-9][0-9]%', YOUR_COLUMN_NAME), 50))) AS MONTHARCHIVED,
datepart(YEAR, CONVERT(date, SUBSTRING(YOUR_COLUMN_NAME, patindex('%[0-9][0-9]/[0-9][0-9]/[0-9][0-9]%', YOUR_COLUMN_NAME), 50))) AS YEAR_ARCHIVED
FROM
TABLEABC
Thanks Shiven:) If Answer is Helpful, Please Vote
Similar Messages
-
Dear all,
I have the following comment in column in one my table. Is there a smart way to extract the
DATE from the text, It may be in any date format.
'My comments (written submissions sent on 29-SEP-2006)'
'My comments are 24 September 2009 9.30 '
'My comments, 15.12.2008'
'My comments on 25.11.2008'
'form 2008/ My comments 11 JUN 2007'
'my comment on 4-4-2008'
'My comm. -extens.not possible - 23.03.2007 09:00'
'MyComm.on 04/04/06'
'My comments on 15 Sep 2009 at 9.15h at EPO, changed on 16 sep 09' -- in this case 15 Sep 2009 is needed
Please share your views.
Regards,
Vikash KumarHi,Try with this one
SELECT REGEXP_SUBSTR('My comments (written submissions sent on 29-SEP-2006','[0-9]+[-./[:space:][:alnum:]][[:alnum:]]+[-./[:space:][0-9]]*[0-9]*') a FROM dual
union all
SELECT REGEXP_SUBSTR('My comments are 24 September 2009 9.30 ','[0-9]+[-./[:space:][:alnum:]][[:alnum:]]+[-./[:space:][0-9]]*[0-9]*') a FROM dual
union all
SELECT REGEXP_SUBSTR('My comments, 15.12.2008','[0-9]+[-./[:space:][:alnum:]][[:alnum:]]+[-./[:space:][0-9]]*[0-9]*') a FROM dual
union all
SELECT REGEXP_SUBSTR('My comments on 25.11.2008','[0-9]+[-./[:space:][:alnum:]][[:alnum:]]+[-./[:space:][0-9]]*[0-9]*') a FROM dual
union all
SELECT REGEXP_SUBSTR('form 2008/ My comments 11 JUN 2007','[0-9]+[-./[:space:][:alnum:]][[:alnum:]]+[-./[:space:][0-9]]*[0-9]*') a FROM dual
union all
SELECT REGEXP_SUBSTR('my comment on 4-4-2008','[0-9]+[-./[:space:][:alnum:]][[:alnum:]]+[-./[:space:][0-9]]*[0-9]*') a FROM dual
union all
SELECT REGEXP_SUBSTR('My comm. -extens.not possible - 23.03.2007 09:00','[0-9]+[-./[:space:][:alnum:]][[:alnum:]]+[-./[:space:][0-9]]*[0-9]*') a FROM dual
union all
SELECT REGEXP_SUBSTR('MyComm.on 04/04/06','[0-9]+[-./[:space:][:alnum:]][[:alnum:]]+[-./[:space:][0-9]]*[0-9]*') a FROM dual
union all
SELECT REGEXP_SUBSTR('My comments (written submissions sent on 29SEP2006','[0-9]+[-./[:space:][:alnum:]][[:alnum:]]+[-./[:space:][0-9]]*[0-9]*') a FROM dual
union all
SELECT REGEXP_SUBSTR('My comments (written submissions sent on 29SEP.2006','[0-9]+[-./[:space:][:alnum:]][[:alnum:]]+[-./[:space:][0-9]]*[0-9]*') a FROM dual
union all
SELECT REGEXP_SUBSTR('My comments (written submissions sent on 29022006','[0-9]+[-./[:space:][:alnum:]][[:alnum:]]+[-./[:space:][0-9]]*[0-9]*') a FROM dual -
Extracting data from a string of characters
Hi,
I have a problem that I am having difficulty solving, if anyone has any bright ideas it would be a great help.
I have a description field in one of my tables and the description would read something like
my website can be found at www.mywebsite.com, and it is great
I want to be able to extract the web address from this sentance, so the result would be
www.mywebsite.com
I can do this specific for one sentance but I can't find a way to do it for many different sentances.
cheers in advanceIf you're using 10g, you probably want to do something with regular expressions:
SQL> with strings as (
2 select
3 'my website can be found at www.mywebsite.com, and it is great' str
4 from
5 dual
6 union all
7 select
8 'my website can be found at WWW.myWebSite.com, and it is great'
9 from
10 dual
11 union all
12 select
13 'our web address is www.mywebsite.co.uk' str
14 from
15 dual
16 union all
17 select
18 'http://www.mywebsite.com/great'
19 from
20 dual)
21 select
22 s.str
23 , regexp_substr(s.str, 'www\.[a-z0-9-\.?]*', 1, 1, 'i') extr
24 from
25 strings s
26 /
STR EXTR
my website can be found at www.mywebsite.com, and it is great www.mywebsite.com
my website can be found at WWW.myWebSite.com, and it is great WWW.myWebSite.com
our web address is www.mywebsite.co.uk www.mywebsite.co.uk
http://www.mywebsite.com/great www.mywebsite.comYou'd be better asking this kind of thing on the PL/SQL (and definitely better asking someone other than me anything further about regular expressions!) -
How to extract data from text file to database table
Hi ,
I am trying to upload data in text file to database table using GUI_UPLOAD function .what would be the program for that.
thanks in advance.Hi,
I don't think you have a standard sap program to upload data from file to database table...
Instead you can create a custom program like this..
DATA: T_FILEDATA(1000) OCCURS 0 WITH HEADER LINE.
DATA: T_ZTABLE LIKE ZTABLE OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'C:\TEST.TXT'
tables
data_tab = T_FILEDATA
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT T_FILEDATA.
T_ZTABLE = T_FILEDATA.
APPEND T_ZTABLE.
ENDLOOP.
MODIFY ZTABLE FROM TABLE T_ZTABLE.
COMMIT WORK..
Thanks,
Naren -
Extract date from string in T-SQL
Hi,
I am having one field(AT_TEXT) in my database that has below kind of values. I want to extract date from this string but the issue is all rows has different format.
1)One Month Lttr sent on 3/12/2009 due to
2)One Month Letter sent on 1/15/2009 due to
3)One Month letter sent on7/15/2011.The amount due - This has no space between on and 7 and . after yr
4)One Month letter sent on 7/16/12 due to - This has 12 instead of 2012(2 positions after 2nd slash/)
Can anyone please help me to write query to extract date from this string?
VickyHi Jingyang
Li,
I checked your query and it looks good but I have one issue. So when we reverse it, it looks like below and it is talking that $57.80 as a 1st numeric value and try to convert it into date and giving me error.
I realize from your query that you are trying to reverse the value and then try to find out 1st Numeric value from that string, but my whole string has another numeric value at the end, like
"One Month Letter on 1/15/2009 due to non-pmt of prems-amt to avoid DE is $57.80"
So when we reverse it, it looks like below and it is taking that $57.80 as a 1st numeric value and try to convert it into date and giving me error.
"08.75$ si ED diova ot eud tma - smerp fo tmp-non ot eud 9002/51/1 no retteL htnoM enO"
Also sometimes I have $ amount at the end and sometimes I don't have any $ amount at the end, like below,
"One Month letter sent on 10/15/2012 due to non-payment of premiums. The amount due to avoid dise"
Can you please modify your query which takes only date part not the $ amount and give me?
Thank you so much for your help
Vicky -
Extracting data from a SQL Server to BW
Hi Experts,
Can somebody let me know how to extract data from a NON SAP
SQL Server I mean
1. Creating a Source System
2. Connecting to the SQL server
3. Creating datasources and extraction
Kindly help me its urgent
thank you
arshad.Hi Ingo,
What I suggest is instead of extracting it to a file, can you use the function module which replicates this data to the mobile clients and use this function module to call the select statement. If a mobile client is able to access this info, then it must be doing a RFC call to some system whose logical system would have been in SAP as well. This is an assumption.
May be if you could call the same function to derive the required data instead of extracting it to a file and then uploading it.
Regards,
Srikanth -
Extracting data from Oracle GL and importing to FDM using ERPI adapter
Hi,
I am also trying to use ERPI adapter to directly extract data from Oracle GL. I am not finding sufficient information on this. It would be great if anyone can help me in this.
I have one more doubt: Can we call the stored procedures in the FDM custom scripts, If so can I get the syntax of the script...I really don't have idea on this FDM part. I was working till now with the Flatfile input, But my client wants to make this change in the existing system. Accessing/Extracting data from Oracle GL. Experts who knows it can pls guide me.
I am using FDM 11.1.2 and ERPI associated with 11.1.2.
Thanks in Advance.
[email protected]Hi,
Is it possible to execute the stored procedures in FDM. Currently we are extracting data from oracle GL using SQl procedures (constaller tool is user to create the inteface) and storing the required data in the intermediate table in oracle GL, From which we are extracting data into a flat file and then loading it to FDM.
So my question: is it possible to invoke the stored procedure from FDM scripts, If so can you pls let me know how to do that...
Thanks In Advance,
[email protected] -
Extract data from a BW 7.0 cube to a SQL DB using Data Services XI
Hi Gurus,
We are trying to extract data from a BW 7.0 cube to a SQL DB using Data Services XI, the issue is that we can not read text without making "joins" between SID in the fact table and the master data tables. Do you know if it is posible to read text in a natural way?
Best RegardsThanks Wondewossen,
As you know, the DataStores (Data Services) provide access to:
1.-Tables
2.-Functions
3.-IDOCs
4.-Open Hub Tables
We are trying to extract data using the first one (Tables), not using Open Hub.
Best Regardas -
Is it possible to save / extract data from a MS SQL database 2008 using lookout 6.2?
Now a days we are saving / extracting data in a excel spreadsheet, but we would like to do that using a database because it is better.You can use ODBC connection to work with SQL Server database.
Use SQLExec object to execute the SQL statement. Here is a KB about the SQL statement.
http://digital.ni.com/public.nsf/allkb/4ADEEA04CD24AE0B862565E20002A16F?OpenDocument
To write data to spreadsheet is more straightforward because Lookout has built-in spreadsheet object. But you need to write SQL statement by yourself to interact with other database.
To read the data back is the same way. Just use "select" SQL statement to query. You can use Datatable object to query.
The "Data Source" can be "DSN = data source name;". The data source name is configured in Control Panel->Administrative Tools->Data Sources(ODBC).
Ryan Shi
National Instruments -
How to Extract data from a transaction..
Hi All
There are some transactions and report programs which are used daily to produce some results and the requirement is to extract that data into BW
so how can we extract information from a transactions and programs
Any help will be really appreciated and ofcourse rewarded ...
Regards
LisaYou can use the following methods
Method 1:
1> Create another ABAP program with logic to calculate all the fields, but instead of writing the result data to screenm, it should store it in a internal table and pass it to the extract structure.
2>Create a InfoSet query based on your ABAP program and use that InfoSet
3> Create a DataSource based on this InfoSet query and extract data from the DS to you ODS/Cube
In this method there is no Intermediate storage used.
Method 2:
1> Modify the report/transaction program to store the required data into a Transparent Table (u can create one from SE11) in addition to displaying on the screen.
2> Create a View on this transparent table (from SE11)
3> Create a DataSource on that view and extract data from that into your ODS/Cube.
Here, the required data is stored in the Table in addition to the DataTarget.
But, to implement either of these solution, you will need a decent ABAP knowledge. Else, it will give you a tough time!
Good luck!
Regards,
Sree -
Hi,
I am trying to extract data from multiple CSV files to SQL into a single table. The data type of all the columns in SQL table is nvarchar(MAX). I am able to extract the data from the flat files but some of the data(on extraction) is
corrupt including question marks(?) and other invalid special characters. Also I tried selecting the UTF-8, 65001(Unicode) format but the problem still persists. Also I tried using data converter but no use.
I checked with the data in the flat file but there is no data with question mark(?) or any other special characters.
The separator in the flat file is Comma(,)
Please help.
Thanks in advace.The source system and application determines the code page and encoding. Is it Windows, Unix, Mainframe or some other type?
Unicode files sometimes begin with a byte order mark (2 bytes) to indicate little or big endian. If you open the file in notepad and then select save as, the encoding in the dialog will show the encoding notepad detected based on the BOM. If
that is ANSI instead of Unicode or UTF-8, you will need to know the code page the source system used when the file was created.
Dan Guzman, SQL Server MVP, http://www.dbdelta.com -
Hi i am new to labview
I want to extract data from a text file and display it on the front panel.
How do i proceed??
I have attached a file for your brief idea...
Attachments:
extract.jpg 3797 KBRoopeshV wrote:
Hi,
The below code shows how to read from txt file and display in the perticular fields.
Why have you used waveform?
Regards,
Roopesh
There are so many things wrong with this VI, I'm not even sure where to start.
Hard-coding paths that point to your user folder on the block diagram. What if somebody else tries to run it? They'll get an error. What if somebody tries to run this on Windows 7? They'll get an error. What if somebody tries to run this on a Mac or Linux? They'll get an error.
Not using Read From Spreadsheet File.
Use of local variables to populate an array.
Cannot insert values into an empty array.
What if there's a line missing from the text file? Now your data will not line up. Your case structure does handle this.
Also, how does this answer the poster's question? -
Using SQL Server 2012 SSIS to Extract Data From SAP
Hi
What is the current best practice for using SQL Server 2012 SSIS to extract data from SAP R3? Please note we are looking for a solution that does not use SAP BW or SAP OHS.
Ideally we would like to build our ETL SSIS process to make a .NET call to an SAP RFC procedure and avoid using web services.
With SS2012 can we use any of these without using SAP BW:
- SAP .NET Connector
- MS ADO .NET
- BizTalk .NET 3.0 Adapter
Thanks and take care,
ShayneHi Shayne,
You can use the .NET Framework Data Provider for mySAP Business Suite along with SQL Server Integration Service (SSIS) to import data from an SAP system into SQL Server database tables, flat files, or other compatible destination types. You can create an SSIS
package that can be executed to import data from an SAP system.
You must use the SQL Server Import and Export wizard to import data into the SQL Server database. You must provide a select query to specify data to be imported. The query must confirm to the semantics supported by the Data Provider for SAP. You can start the
SQL Server Import Export Wizard either from the SQL Server Management Studio or from an Integration Service project in Visual Studio. Detail steps please see:
Importing SAP Data Using SQL Server Management Studio:
http://msdn.microsoft.com/en-us/library/cc185161(v=bts.10).aspx
Importing SAP Data Using Visual Studio:
http://msdn.microsoft.com/en-us/library/cc185254(v=bts.10).aspx
Please feel free to ask if you have any question.
Thanks,
Eileen
Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other community members reading the thread. -
Extracting data from Express to SQL Server
is there a way to extract data from a Personal Express (v5)
database into MS SQL Server (2000) using a DTS package ? I
haven't found any references to an Express ODBC driver so I
doubt it's possible and I may have to use SNAPI from VB.
thanks.erics44 wrote:
Hi
i am looking after a set of schemas and reports. One report is based on data in an sql server that is periodically extracted from oracle.
How might this be done? I am struggling finding the object that does thisThere could be any number of ways. It could be SQL Server connecting to the oracle database and querying the data directly. It could be a script on the SQL Server server that connects to Oracle and extracts the data. It could be a script on the Oracle server that extracts the data and then pushes it across to the SQL Server server. It could be a completely different script sitting on an unrelated server connecting to both databases. It could be a scheduled job running on the Oracle database that extracts the data and moves it across..... and so the list goes on.
It's unlikely we'll be able to tell you anything as you are the one with access to your servers. -
Extracting data from ms sql data base
Hi Experts,
we have a requirement of extracting data from MS SQL data base,could any one pls help me with the approach to extract data
from ms sql data base(actually we have to extract the data from PRIMAVERA i.e the back end data base is MS SQL data base and the application is built on java)so we have got two options one is using ud connect and the other one is using PI(XI).i came to know the two approach have based on differenct methods,pull and push mechanism.and also for PI,it can be extracted using
real time data acquisition property in dtp and for db connect it don't support real time data acqusition.
so pls guide me,which mechanism would be feasible to extract the data from PRIMAVERA to SAP BI.and can you suggest with methods is more efficient.
Thanks in advance.Hi thanks for the reply,
initially we tried with db connect,but our Bi system(oracle) is mount on unix OS and the Primavera(MS Sql DB)is on windows OS.so we could not found the data base shared library once if the DB client is installed on the application server.so we are working around with the other possibilities,so can you suggest me which could be favarable in our case.
Thank You.
Maybe you are looking for
-
I am unable to open Calendar on my iMac - this occurred after installing Security Update 2015-002. I don't know if related. A message pops up after several minutes saying Calendar quit unexpectedly (but it never really opens). How do get Calendar b
-
Nokia C3 How can I make sure it only connects thro...
Ive just got this phone for my daughter on Vodaphone contract, I am really worried however that it is going to randomly connect itself to the internet like my old Nokia 5800 used to! How can I make sure it doesn't, I don't want it to end up costing m
-
my ipod touch was dropped on the ground, screen is cracked, won't even turn on when it's being charged, what to do?
-
Finder refuses to show file-specific iconHello Folks
Hello Folks, I'm having a little problem with certain types of files: The problem is that the corresponding icons from the application used for reading that files are not being displayed when assigning an application to that file. For example: when I
-
How do I make a 3D shape or mesh transparent?
I have a photo of a bottle I need to mock up with a label I designed. Warping placed graphics isn't doing the trick, it looks wonky. I made a 3D mesh and loaded my label as a texture onto it so that it matches the shape and angle of the bottle. Probl