Create Date Field From Substring Of Text Field

Jul 20, 2005

I am trying to populate a field in a SQL table based on the values
returned from using substring on a text field.


Field Name = RecNum
Field Value = 024071023

The 7th and 8th character of this number is the year. I am able to
get those digits by saying substring(recnum,7,2) and I get '02'. Now
what I need to do is determine if this is >= 50 then concatenate a
'19' to the front of it or if it is less that '50' concatenate a '20'.
This particular example should return '2002'. Then I want to take the
result of this and populate a field called TaxYear.

Any help would be greatly apprecaietd.


View 2 Replies


Substring On Text Field

Jan 7, 2005


According to the docs, when using substring on a text field (not varchar):

substring (<text>, start, length)

...the length in this case, represents BYTEs as opposed to number of characters. So my question is, how many bytes per character (or characters per byte)....or is this a possible conversion?


View 3 Replies View Related

Compare Date Field To Text Field

Mar 27, 2008


I am very new to using SQL. Our department usually uses Brio to query the various databases under our control. However, I have recently come against a problem that prompted me to create a custom SQL query which works well as far as it goes. My problem is looking for specific conditions in billing information I receive monthly. I would like to compare on of the date fields contained in the database with a field in the form of YYYYMM (200710, for October 2007) I have created a custom column generator that forms a date from the YYYYMM. I would like, however, do the translation on the fly and make the comparison during the query. The problem is that query without the date check returns a mass of data, only about 1 percent of which is what I want.

The beginning of the SQL query looks like this:

FROM From.T_Crs_Tran_Dtl WHERE T_Crs_Tran_Dtl.Crs_Bill_Yr_Mo IN ('200710', '200711', '200712') AND ((T_Crs_Tran_Dtl.Crs_Cde IN ('1G', '1V') AND (T_Crs_Tran_Dtl.Dptr_Dte < LastDay(ToDate(Substr ( Crs_Bill_Yr_Mo, 5, 2 )& "/1/"&Substr ( Crs_Bill_Yr_Mo, 1, 4 )))) AND (T_Crs_Tran_Dtl.Prev_Stats_Cde IN (' ', 'TK', 'TL') AND T_Crs_Tran_Dtl.Cur_Stats_Cde IN ('TK', 'TL') AND T_Crs_Tran_Dtl.Std_Tran_Typ_Cde='B') OR (T_Crs_Tran_Dtl.Prev_Stats_Cde='UN' AND T_Crs_Tran_Dtl.Cur_Stats_Cde='XX' AND€¦

It is the €ś(T_Crs_Tran_Dtl.Dptr_Dte < LastDay(ToDate(Substr ( Crs_Bill_Yr_Mo, 5, 2 )& "/1/"&Substr ( Crs_Bill_Yr_Mo, 1, 4 )))) AND€? part of the query that is just plain wrong. The business part of this statement takes the YYYYMM field and turns it into a date which is the last day of YYYYMM.

I hope someone out there can help me with making this comparison.

I appreciate your help.


View 8 Replies View Related

Transact SQL :: Return Field When A Field Contains Text From Another Field

Aug 25, 2015

I'm new to SQL and I'm trying to write a statement to satisfy the following:

If [Field1] contains text from [Field2] then return [Field3] as [Field4].

I had two tables where there were no matching keys. I did a cross apply and am now trying to parse out the description to build the key.

View 8 Replies View Related

How To Add Date Field And Time Field (not Datetime Field )

May 4, 2006

Good morning...

I begin with SQL, I would like to add a field that will be date like 21/01/2000.

Actually i find just "datetime" format but give me the format 21/01/2000 01:01:20.

How to do for having date and time in two different field.

Sorry for my english....


A newbie

View 3 Replies View Related

SQL 2012 :: UK Date In Text Field As True Date

Jul 14, 2014

I have a date held in a varchar field in a temporary sql table and I want to convert it into a sql date and it doesn't work. I can replicate this as below -

So I run

cast ('14/02/2014' as date)

and I get a conversion failed error.

View 2 Replies View Related

Create Rich Text From A Select And Save It In A Field

Jun 28, 2007

I want to execute some queries inside a stored procedure, get the data and create from them some strings with formatted parts (bold, italic, underline, different color fonts) and save them in a text field. These strings are going to be displayed in some DBRichText control in a database application built with Delphi. Is there an easy way to create these complex rtf formats in MSSQL
or some ideas regarding this problem?

Best Regards,
Manolis Perrakis

View 1 Replies View Related

Text Field To Display Date Parameter Chosen

Mar 26, 2008


I'm attempting to use the following code to display either 'All' or the date value selected by the user from a Report parameter;

=iif(Parameters!FromCheckOutDateDate.Value.ToString = "[Check Out Date].[Date].[All]", "All", "From Date: " + Parameters!FromCheckOutDateDate.Value.ToString.Substring(26,10))

This is throwing an error ('#Error').

I can use the following code with no error, though its not as useful;

=iif(Parameters!FromCheckOutDateDate.Value.ToString = "[Check Out Date].[Date].[All]", "All", "Not all")

I can even use this to display the selected value (i.e. 2007-01-01);


Why can't I use them both in my iif statement?

Can someone please help?

View 2 Replies View Related

Access Memo Field To SQL Server Text Field

Nov 19, 2006


I'm importing an Access database to SQL Server 2000.
The issue I ran into is pretty frustrating... All Memo fields that get copied over (as Text fields) appear to be fine and visible in SQL Server Enterprise Manager... except when I display them on the web via ASP - everything is blank (no content at all).

I didn't have that problem with Access, so I ruled out the possibility that there's something wrong with the original data.

Is this some sort of an encoding problem that arose during database import?
I would appreciate any pointers.

View 14 Replies View Related

MS Access Memo Field To SQL Server Text Field

Aug 20, 2006

Hi all,

i've a reasonable amount of experience with MS Access and less
experience with SQL Server. I've just written an .NET application that
uses an SQL Server database. I need to collate lots of data from around
the company in the simplest way, that can then be loaded into the SQL
Server database.

I decided to collect the info in Excel because that's what most people
know best and is the quickest to use. The idea being i could just copy
and paste the records directly into the SQL Server database table (in
the same format) using the SQL Server Management Studio, for

Trouble is, i have a problem with line feed characters. If an Excel
cell contains a chunk of text with line breaks (Chr(10) or Chr(13))
then the copy'n'paste doesn't work - only the text up to the first line
break is pasted into the SQL Server database cell. The rest is not
pasted for some reason.

I've tried with MS Access too, copying and pasting the contents of a
memo field into SQL Server database, but with exactly the same problem.
I've tried with 'text' or 'varchar' SQL Server database field formats.

Since i've no experience of using different types of databases
interacting together, can someone suggest the simplest way of
transferring the data without getting this problem with the line feeds?
I don't want to spend hours writing scripts/programs when it's just
this linefeed problem that is preventing the whole lot just being
cut'n'pasted in 5 seconds!



View 6 Replies View Related

Export Access Memo Field To SQL Text Field

May 30, 2006


Can anyone point me any solution how to export a MEMO field from an Access database to a TEXT field from an MS SQL Server 2000. The import export tool from SQL server doesn't import these fields if they are very large - around 9000 characters.


View 1 Replies View Related

Pass In Null/blank Value In The Date Field Or Declare The Field As String And Convert

Dec 30, 2003

I need to pass in null/blank value in the date field or declare the field as string and convert date back to string.

I tried the 2nd option but I am having trouble converting the two digits of the recordset (rs_get_msp_info(2), 1, 2))) into a four digit yr. But it will only the yr in two digits.
The mfg_start_date is delcared as a string variable

mfg_start_date = CStr(CDate(Mid(rs_get_msp_info(2), 3, 2) & "/" & Mid(rs_get_msp_info(2), 5, 2) & "/" & Mid(rs_get_msp_info(2), 1, 2)))

option 1
I will have to declare the mfg_start_date as date but I need to send in a blank value for this variable in the stored procedure. It won't accept a null or blank value.

With refresh_shipping_sched
.ActiveConnection = CurrentProject.Connection
.CommandText = "spRefresh_shipping_sched"
.CommandType = adCmdStoredProc
.Parameters.Append .CreateParameter("ret_val", adInteger, adParamReturnValue)
.Parameters.Append .CreateParameter("@option", adInteger, adParamInput, 4, update_option)
.Parameters.Append .CreateParameter("@mfg_ord_num", adChar, adParamInput, mfg_ord_num_length, "")
.Parameters.Append .CreateParameter("@mfg_start_date", adChar, adParamInput, 10, "")
Set rs_refresh_shipping_sched = .Execute

Please help

View 6 Replies View Related

How To Convert Datetime Field To A Date Field So Excel Recognize It As Data Type

May 17, 2015

I embedded a SQL query in excel that gets some datetime fields like "TASK_FINISH_DATE" .

How can I convert a datetime field to a date field in SQL in a way that excel will recognize it as a date type and not a text type?

I tried:

**all of the above returned text objectes in excel and not date objects.

View 3 Replies View Related

Informix Date Type Field To SQL Server Datetime Field Error

Oct 17, 2007

I am trying to drag data from Informix to Sql Server. When I kick off the package
using an OLE DB Source and a SQL Server Destination, I get DT_DBDATE to DT_DBTIMESTAMP
errors on two fields from Informix which are date data timestamp part

I tried a couple of things:

Created a view of the Informix table where I cast the date fields as datetime year to fraction(5), which failed.

Altered the view to convert the date fields to char(10) with the hopes that SQL Server would implicitly cast them
as datetime but it failed.

What options do I have that will work?

View 1 Replies View Related

Substring From A Name Field

Sep 24, 2013

We capture the firstname of a person along with their middle intial in our contacts table . How do i use the substring function to get just the firstname and omit the middle initial

Sample Data

Jennifer K
Jason R
Samuel V

I want just the firstname without the space and middle initial

Required Format

View 4 Replies View Related

SQL Substring On DateTime Field

Apr 11, 2006

Can anyone tell me how to perform a substring operation on a DateTime field. I'm using SQLServer. I have read that you may have to use casts but I have thus far been unable to get that to work.
My statement:
SELECT EventDate FROM tblEvent WHERE Category = 'GE';
I just want to cut the hours, minutes and seconds off, so that I am left with just the date element.
Thanks all.

View 1 Replies View Related

Extracting Substring Into New Field

Dec 20, 2007

I am trying to populate two fields in my table with the first 6 characters in an existing field with the following command:

SELECT dimension_elist,
SUBSTRING(dimension_elist FROM 1 FOR 6)
AS BU_Number
SUBSTRING(dimension_jde_pl FROM 1 FOR 6)
AS Acct_Number

The result is an error:
Server: Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'FROM'.

I am fairly new to SQL so I am probably missing something basic.

Does anyone have any thoughts?

View 2 Replies View Related

Substring'ing A Number-field

Jul 20, 2005

Hi :) and thanx for reading my post.I have to create a view based on a character in a number-field (fnr)which is 11 char's long. I have to get character nr "7".The problem is that i cannot use :--> SELECT fnr FROM table WHERE substring(fnr,7,1)since it's not a string.Any other way i can solve this ? Would be greatly and insanely happy ifanyone could help me out with a sample code or something.!Best regardsMirador*** Sent via Developersdex ***Don't just participate in USENET...get rewarded for it!

View 1 Replies View Related

Convert Var Char Field To Date Field

Sep 27, 2005


I need to convert a var char field to date field (DD/MM/YYYY)

Current convertion format:
CAST(Report_Date as DATETIME)

How can i convert to Date field with date format of DD/MM/YYYY?


Onn Onn

View 2 Replies View Related

SQL Server 2012 :: Using Substring For A Destination Field?

Aug 23, 2014

I have a Function where I want to put a character in a particular position in a Destination string. For example, I have a 5 character field containing, say, "12345". I would like to put the letter "A" in the third position resulting in "12A45". I'm trying the following

DECLARE @RetVal as varchar(5)
SET SUBSTRING(@RetVal,3,1) = 'A'

I'm getting a compiler error

"incorrect syntax near '@RetVal'. Expecting '(' or SELECT"

Am I using the wrong Function to do this? If so, what should I be using?

View 2 Replies View Related

Should I Use Text Field Or Binary Field ?

Jun 1, 2008

Application is ocr'ing tiff image files and then storing the resultant text data in a text field in SQL 2005 database. This field is then used with the full text catalog.

All works fine,

However, am I using the correct field type to store the text files for efficiency and space saving?

If I use a binary field, does this reduce the size of the database by compressing the text data in the binary field? Also, is there a limit as to the size of text file that I could store in a binary field?

It would be good to get feedback on this before I go too far down the wrong road.

So, text field to store the text data or binary field to store the actual text file?

View 12 Replies View Related

SUM If Date Field &&>=inputted Field?

Mar 24, 2008

I need help. I'm one step short of getting what I need.
Here is what I have:
SELECT FilteredIncident.accountidname, FilteredIncident.ticketnumber, FilteredIncident.createdon, FilteredIncident.modifiedon, FilteredIncident.new_enduserfirstname,
FilteredIncident.new_enduserlastname, FilteredIncident.responsiblecontactidname, FilteredIncident.statuscodename, FilteredIncident.title,
SUM(FilteredActivityPointer.actualdurationminutes) AS TotalTime
FROM FilteredActivityPointer LEFT OUTER JOIN
FilteredIncident ON FilteredIncident.incidentid = FilteredActivityPointer.regardingobjectid
GROUP BY FilteredIncident.accountidname, FilteredIncident.ticketnumber, FilteredIncident.createdon, FilteredIncident.modifiedon, FilteredIncident.new_enduserfirstname,
FilteredIncident.new_enduserlastname, FilteredIncident.responsiblecontactidname, FilteredIncident.statuscodename, FilteredIncident.title
HAVING (FilteredIncident.accountidname = @accountid) AND ((FilteredActivityPointer.actualstart >= @billtime) OR (FilteredIncident.statuscodename <> N'Problem Solved'))

This pulls everything that started after a certain date (@billtime) AND everything that is not closed. This is what I want; however, I need the SUM(FilteredActivityPointer.actualdurationminutes) AS TotalTime to only calculate the TotalTime after the @billtime regardless of the status. I can easily code in the date in the format 03/04/2008 but I haven't figured out how to do it successfully. I tried an IIF within the SUM and just got a syntax error (I'm assuming it is because FilteredActivityPointer.actualstart is a date/time.)

Essentially, I need a report that shows all open tickets in the system AND all tickets that have been worked on since a specific date regardless of status that only totals the time spent during that date range.
Many thanks to anyone who can help.

View 1 Replies View Related

Problem With Text Field: Text Input Too Long, Weird Characters

May 15, 2006


Im a programmer for an university webportal which uses php and msssql.
When an user creates a new entry and his text is too long the entry is cut short and weird characters appear at the end of the entry.

For example:

How can I set the text limit to unlimited?
Could it be something else?
Is there a way of splitting an entry to several text fields automatically?

Thanks in advance for any help you can give me,

View 3 Replies View Related

SQL 2012 :: Text Qualifier Inside A Text Qualified Field

Mar 12, 2015

In SQL 2005 if i was trying to insert some data with a text qualifier inside a text qualified field, it would work, for example:

"Name","ID ","Location","","Comany",""House Name" Road",

In SQL 2012, this fails with the error message, cannot find the text qualifer for field.

To get around this, we are having to import the data into a Dirty Data column of aTEMP table, ID, Dirty Data, Clean data - perform multiple updates and change the text qualifier and ensure they are only changed in the right places so we can keep the ". In this example, we changed the text qualifier to PIPES.

After these updates, we then export the data from CLEAN data back out to CSV, then reimport it into the origional destination table with a new text qualifer.

View 5 Replies View Related

Transact SQL :: Server Text Field Not Returning Full Text

Apr 21, 2015

I have a column in a table that has a type TEXT,when I pull the length of a row it returns 88222 but when I select from that column it dows not show all the text in the result set.

View 3 Replies View Related

How Can I Parse Text Held In MS SQL 2005 Text Field

Apr 24, 2007

Hi,I been reading various web pages trying to figure out how I can extract some simple information from the XML below, but at present I cannot understand it.
I have a MS SQL 2005 database with which contains a field of type text (external database so field type cannot be changed to XML)The text field in the database is similar to the one below but I have simplified it by remove many of the unneeded tags in the <before> and <after> blocks. I also reformatted it to show the structure (original had no spaces or returns)
For each text field in the SQL table contain the XML I need to know the OldVal and the NewVal.
<ProductMergeAudit> <before>  <table name="table1" description="Test Desc">   <product id="OldVal">  </table> </before> <after>  <table name="table1" description="Test Desc">   <product id="NewVal">  </table> </after></ProductMergeAudit>

View 2 Replies View Related

(Urgent) How Get A Text Field And Put The Result Into A Text Var

May 3, 2004

Hi All

Iam trying to Get a text field value i wrote this code

DECLARE @ptrval varbinary(16)
DECLARE @length bigint
SELECT @ptrval = TEXTPTR(Template), @length = LEN(Template)
READTEXT Template.#TEMPLATE @ptrval 0 @length

but i need to put the result into a text var
is that possible or not and if it possible any one could help me with that

View 1 Replies View Related

Adding Text To A TEXT Field (MS-SQL2000)

May 9, 2007

Hi everyone,

I'm extremely new to SQL so be nice

I am attempting to write a script to add onto the end of a text field the words " -- Disposed " (About 60 rows worth).
The field is a TEXT field, so unlike a varchar field I can't just use Update as shown below.


Update AR_Primary_asset
Set AR_Primary_asset.description = AR_Primary_asset.description + ' -- Disposed'
Where AR_Primary_Asset.ASSET_REF in ('1','2','4')

I found on the Mircosoft pages about UPDATETEXT, but this only seem to work to update one row (In the case below Asset_ref = 3, was the only row effected) .


DECLARE @Dispose binary(16)
WHERE AR_Primary_Asset.ASSET_REF in ('1','2','3')

UPDATETEXT AR_PRIMARY_ASSET.DESCRIPTION @ptrval null null ' -- Disposed'

So i wrapped it into a cursor, this worked on my test SQL server which runs SQL2005.


DECLARE @Dispose varbinary(16)

FROM AR_Primary_Asset
Where AR_Primary_Asset.ASSET_REF in('1','2','3')

OPEN cursor1

INTO @Dispose


UPDATETEXT AR_Primary_Asset.DESCRIPTION @Dispose NULL NULL ' -- Disposed'

INTO @Dispose

CLOSE cursor1

But when it was run on our SQL2000 server it gave the following error message

Quote: Msg 403, Level 16, State 1, Line 1

Invalid operator for data type. Operator equals add, type equals text.

I've never used vars, cursors, updatetext or even text fields before. So maybe I am going about it totally the wrong way.

Is anyone able to tell me a better way to write this? or how to make it compatible to SQL2000?

View 4 Replies View Related

T-SQL (SS2K8) :: Insert Text In A Text Field

Jul 12, 2014

CREATE TABLE [dbo].[instructions](
[site_no] [int] NOT NULL,
[instructions] [text] NULL
Select top 3 * from instructions


20Request PIN then proceed
21Request PIN if wrong request name
22Request PIN allowed to use only numbers

All text instructions start with “Request PIN” but after that the text are different for every site_no

I need insert in all site_no rows and after the “Request PIN” the text “and codeword” keeping the current rest of text

Desired output

20Request PIN and codeword then proceed
21Request PIN and codeword if wrong request name
22Request PIN and codeword allowed to use only numbers

View 3 Replies View Related

How Do I Convert A Unix Date/Time Field To A Date When The The SQL DB Stores That Data As Char 11?

Nov 13, 2007

Hi there.
I'm trying to extract data from my SQL server & everything in the script I've got is working (extracting correct data) except for one field - which is for the most part it's off by +2 days (on a few occasions - I see it off by just +1 day or even +3, but it's usually the +2 days).

I'm told that it's due to the conversion formula - but - since SQL is not my native language, I'm at a bit of a loss.

The DB table has the date field stored as a type: CHAR (as opposed to 'DATE')
Can anyone out there help?

Please advise. Thanks.


View 1 Replies View Related

Reporting Services :: Formatting A Date Field To Just Show Date Not Minutes?

Jul 6, 2015

A date field in a report returns the date value as:

2015-07-01 13:30:27.000

Is there any way I can script this to appear as:

01 July 2015 (or 01-07-2015 or 01/07/2015)  - basically to cut out the hours, minutes and seconds?

The best I have managed is: CONVERT (varchar(17),DATE,113) AS Date1 but this still leaves me with:

01 July 2015 13:30

View 9 Replies View Related

Updating Database Date Field Results In Date Value Of 01/01/1900

Jun 18, 2007

Brand new to this, so please bear with me.I'm using the following code fragment to update a datetime field on a SQL Server 2005 database table:cmd.CommandText = "Update Projects Set EntryDate = " & Convert.ToDateTime(txtEntryDate.Text)cmd.ExecuteNonQuery()The result of the update operation is the the database field contains the value "1900-01-01 00:00:00:000".  This probably means that I passed nulls to SQL; however, I see a valid date in the txtEntryDate field on my web form (i.e., "06/18/2007").  I also did a "Response.write" to display the txtEntryDate and it looks Okay.Can someone tell me what I'm doing wrong?Thanks!Using Visual Web Developer 2005 Express.

View 1 Replies View Related

SQL Server 2012 :: Script To Specify Date Field To Use For Activity Date

Jun 2, 2014

I'm writing a view to check record counts in a table that has numerous datasets and therefore various "Activity Dates". Is it possible as part of the SQL statement to have a CASE statement for example so that it can identify the field to use as the activity date?

The field to use is being identified using a seperate table so at the moment I have CASE WHEN FieldToUse = '2' THEN MapCol ELSE '[Activity_Date]' END, where FieldToUse = '2' identifies the date field to use and the MapCol data is the field name to be used as the activity date.

Is this even possible?

View 3 Replies View Related

Copyrights 2005-15, All rights reserved