Getting An Integer Range Out Of A String Field

Oct 9, 2007



We have account numbers that are string values, looking like: "01.02.02.00.0040.000.000".

We need to parse individual segments and pull out a range of values treating the segment like an integer. For example we would like all accounts that have the fifth segment ranging in values from .0040. through .0060. inclusive.

We've been trying to do something with the like clause: LIKE '__.__.__.__.[0-0][0-0][4-6][0-0]'.

We want 40 through 60 but we're getting 40, 50, and 60. If we change the last bracket to [0-9] we get 40 through 69.

Does anyone have any suggestions as to either fix our like clause or another approach?

Thanks.

John

View 4 Replies


ADVERTISEMENT

Converting An Integer Field Into An Identity Field

Sep 14, 2006

I have a table with an integer field (contains test values like 2, 7,8,9,12,..) that I want to convert to an Identity field. How can this be done in t-sql?

TIA,



Barkingdog





View 1 Replies View Related

Help With Integer Field

Oct 7, 2004

hi all,

i have an autonumber field (primary key) and another integer field as part of a table. What i want to do is when a record is created, the default value of the integer field should be the_autonumber+1000 for eg record with pk 82 will have an integer field that's automatically 1082. Would it be possible to do this ? Thanks in advance.

View 2 Replies View Related

How To Convert A Hex String To An Integer?

Feb 1, 2000

Hi folks,
I'm trying to import data from a text file (UnicodeData.txt) into
an SQL table. Some of the fields are unicode values (16 bits)
expressed as four hexidecimal digits. I've succeeded in importing
the data as character strings, but I have not found a way to convert
them into numbers. (They could be stored as int or nchar.)
I've tried convert(binary/int/whatever, string); E.g.
select convert(int, '0x1111') from import_unicode
gives the error
Syntax error converting the varchar value '0x1111' to a column of data type int.

I could write code to strip off one character at a time, convert the
hex digit to a decimal value, shift left, etc., but I find it hard
to believe that's the best way.

Any help is appreciated. Please email answer to lars_huttar@sil.org
as I don't read this board.

Thanks,
Lars Huttar
lars_huttar@sil.org

View 3 Replies View Related

Bit Field Vs. Integer With Nulls

Aug 27, 2004

If I have a field where 99.9% of the time the answer is going to be "No", would I be better, in terms of disk space, using:

A bit field

OR

A tiny int field, with a NULL for the 99.9% that are "NO", and a 1 for those that are "YES".

I'm using SQL Server 7.0.

My application developer has no preference.

Thanks.

View 4 Replies View Related

Update On A Integer Field

May 29, 2006

Hi everybody,
Could someone help me ???
Iam starting with sql

My problem ..

Ihave a table Table_customer

In this table a column Table_customer.no
This column contain 8000 rows.
with customer numbers: like 30789
I would like to modify once all this row adding just before the number
a value to all these rows.This value will be a 60
So will have instaed of 30789 a 6030789
This column is an integer.

I have try a simple select wich give me this result
How i can do this with update ?
probably i have to convert fisrt to caracters

select kunr,nov_kunr=
'30'+ltrim(str(kunr))
from event
where kunr is not null

Thank

View 3 Replies View Related

Problem Converting String To Integer

Nov 19, 2006

Hi, I need to convert the values entered into textboxes by the users before I can insert into db.have tried the following. Dim eventnum As string 'tried using integer makes no difference what i declare the variable aseventnum = Convert.ToInt32(txteventnum.Text)This value needs to be inserted into the field event_number wich is datatype int I get the following error message when I try to insert.  Conversion failed when converting the varchar value 'eventnum' to data type int.



Description: An
unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the
error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Conversion failed when converting the varchar value 'eventnum' to data type int.

Source Error:




Line 62: Line 63: ' Execute(query)Line 64: myCommand.ExecuteNonQuery()Line 65: Line 66: 'Close the connection







Source File: C:InetpubloansMemberPagesRequest.aspx.vb    Line: 64


Stack Trace:




[SqlException (0x80131904): Conversion failed when converting the varchar value 'eventnum' to data type int.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +857242 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +734854 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +188 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1838 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) +192 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +380 System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +135 Request.Button1_Click(Object sender, EventArgs e) in C:InetpubloansMemberPagesRequest.aspx.vb:64 System.Web.UI.WebControls.Button.OnClick(EventArgs e) +105 System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +107 System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5102    

View 4 Replies View Related

How To Replace Integer With A String In A Query

Apr 15, 2008

Hi all, In a sql query I need to replace 0 (zero) with "Not rated" ...Can some one help me to do this.In short: how to replace a integer value to a string in a query? is it possible?Thanks for the HelpRamesh 

View 2 Replies View Related

Converting Negative Integer From String To Int

Dec 18, 2006

I'm having an issue using the data conversion task and trying to convert from a negative integer that is bounded by brackets e.g, (1) for -1. I keep getting an error that the value cannot be converted although I've tried all signed integer types.

View 6 Replies View Related

How Do I Convert A String To An Integer For A Parameter?

Dec 14, 2006

I want to convert a string into an interger so that my parameter can get one value, and have a seperate matrix list the value before the value selected.

My parameter is year. The user picks the year. And i want the crashcounts for the year displayed in the matrix. Then i have another matrix with a dataset similiar. I want this seperate Matrix/Dataset to display the previous year.

SO if the user selects 2004 from the dropdown. 2004 is displayed in the first matrix, and 2003 is displayed in the second matrix. The year attribute is in string format, and i cant change it in the cube. So i was told it could be converted in reporting services. with this



=CStr(CInt(Parameters!CrashStatisticalYear.Value)-1)



Question is, where do i put this...and how come when i put it in the parameters expression for the 2nd matrix, i get an error datatype messege? HELP !

View 2 Replies View Related

Contains Keyword For Integer Field Type

Feb 17, 2007

I have a field ID of type integer, I want to put two numbers in that field: 3 and 7, so what I do is just store the number 37.Now, is there a command in SQL server which checks if the ID field contains a number I look for, say 7.Something like a CONTAINS keyword...If there is, could someone please tell me what it is AND tell me a bit more about it :memory usage, (dis)advantages etc.

View 1 Replies View Related

Setting Field To Integer From SqlDataAdapter

Apr 1, 2008

How do i get the result 'puzzle' from the SQL and assign it to Integer and use it to compare with Request.Form ? 
 Protected Sub Page_Load(ByVal sender As Object, _
                      ByVal e As System.EventArgs) Handles Me.Load
 
            Dim connString As String = _           ConfigurationManager.ConnectionStrings("Local_LAConnectionString1").ConnectionString
 
           Dim strsql As String = _
           "Select CustomerID,CustomerNo,dbo.LA_DEC(Passkey) as passcode,dbo.LA_DEC(PuzzleKey) As puzzle, PuzzleFlag, NickName from Customers Where CustomerNo = '" & myAccount & "'"
            Using myConnection As New SqlConnection(connString)                  Dim myCommand As New SqlCommand(strsql, myConnection)
 
                  myConnection.Open()
                   Dim PuzzleDataSet As New DataSet
                  Dim PuzzleAdapter As New SqlDataAdapter(myCommand)                                    //                              <----    Coding here
 
 
 
                   myConnection.Close()
         End Using
 
End Sub

View 7 Replies View Related

Left Pad Zeros To Integer Field

Feb 4, 2004

I have an integer field that ranges from 3 to 6 numbers and I need to left pad leading zeros so the field is always a char(7). What is the syntax to do this? Thanks in advance.

0001234
0012345
0123456
1234567

View 1 Replies View Related

Scripting A Default Value For An INTEGER Field

Jan 28, 2008

Hello,

I am trying to write an SQL command to set the default value of an integer column I have within a table.

ALTER TABLE TableName alter column ColumnName int default 0

Any suggetions?

View 3 Replies View Related

SSIS Convertion Function From Integer To String

Dec 1, 2005

Hello all

View 22 Replies View Related

Validation Error When Converting Integer Zip To String

Sep 17, 2007

I am taking a five-digit zipcode from a database where it is stored as an int, and I would like to store it as a char(5).

I set my OLE DB source to pull from a proc as:




Code Snippet

SELECT

cust.CustomerID as CustomerID,
case

when cust.Zip > 99999 then Null
when cust.Zip < 0 then Null
else REPLICATE('0',5 - LEN(cast(cust.Zip as varchar(5))))

+ cast(cust.Zip as varchar(5))
end as CustomerZip


However, when I do that, SSIS sees the external column as a string of length 8000, and insists on giving me a truncation warning on validation.

I also tried bringing the Zip field in as an int and doing a data conversion in the SSIS data stream. This worked great until I added a Derived Column transform to do the REPLICATE function as above to add leading zeros to the zip code. Once I did that, SSIS decided that there was a chance of truncation again and started with the truncation warnings.

My derived column is:




Code Snippet

REPLICATE("0",5 - LEN(TRIM([CustomerZip]))) + TRIM([CustomerZip])




BTW - I don't think the TRIM() function is really necessary in the above, but I tried it out of desperation and it made no difference.

This is really starting to drive me nuts. Does anyone have any thoughts on how to convert an integer zipcode to a char(5) string with leading zeros without incurring these validation warnings?

TIA

- Steve

View 4 Replies View Related

Char(4) Or Integer For Year / Quarter Field

Sep 3, 2007

Hello,

what's best for year resp. quarter Field, char(4) resp. char(1), integer or other?

Both are part of a composite index.

Thanks
Silas

View 6 Replies View Related

How To Re Number Integer Field Values In A Table

Sep 22, 2014

I am facing problem with re numbering of field records in a table.I am having one table with below records.

sid(identity/primarykey) stickyId(Integer) UserId(integer)
102 0 171
103 1 171
104 2 171
105 3 171

here how to renumbering stickyId values when deleted particular stickyId from UI. Here stickyId field is Integer type only. not primarykey/identity field.

View 3 Replies View Related

Type Cast Error Converting From Integer To String

Oct 30, 2007

I am attempting to convert an integer value to a string using the Derived Column transformation with the following expression on the field:
(DT_STR,10,1252)prod_id

prod_id is an integer. I was able to do this before however, in the past couple of days, this has failed with the following error:
"An error occurred while attempting to perform a type cast."


To my knowledge, I have not changed anything about this particular data flow within the past couple of days. I have verified that the value is coming in as an integer.

Any help would be greatly appreciated.

View 7 Replies View Related

How To Concatenate Two Fields In A Textbox One Integer And Other Charecter Field

Jul 2, 2007

I have the folliwing two fields, want tp concatenate:



=Fields!sequenceno.Value & =Fields!LogType.Value



Thank you very much for the information.

View 3 Replies View Related

SQL Server User Defined Function Treating String As Integer

Oct 3, 2006

I have a User Defined Function in my SQL Server 2000 database which takes a string and adds an integer quantity to it.  The function basically takes the string (string because of first character and spaces) and adds an integer to it creating a new number (starting number and ending number concept).If I pass in a string that has a letter for the first character, it works fine.  However, if the first character is an integer it trims out all 0s and whitespace and ruins the necessary formatting.  Note, the formatting is always the same - x xxx xxxx xx.   Any help or ideas would be appreciated.Example:D 499 8900 01     plus a Quantity of 10 returns D 499 89000 11  which is perfect.However,0 076 0000 03     plus a Quantity of 1 returns  764  764     (it should be 0 076 0000 04)------------------------------------CREATE FUNCTION  [dbo].[NEW_End_NR2](  @OldStr as char(20), @Quantity int )RETURNS @NewNR_Tbl TABLE (New_EndNr char(20) primary key)AS  BEGIN DECLARE @NewStr  char(20)  DECLARE @addNr  integerBEGIN  Set @addNr = @Quantity set @NewStr = (select REPLACE(@OldStr,left(@OldStr, 1),'')) set @NewStr = (select REPLACE(@NewStr,' ', ''))  + @addNr set @NewStr = (SELECT left(@OldStr, 1) +    SPACE(1) + left(@NewStr,3) +    SPACE(1) + left(REPLACE(@NewStr, left(@NewStr,3), ''), 4) +   SPACE(1) + left(REPLACE(@NewStr, left(@NewStr,7), ''), 3)) BEGIN  INSERT INTO @NewNR_Tbl (New_EndNr) VALUES(@NewStr) END END    RETURNEND

View 3 Replies View Related

Integration Services :: Converting String Variable To Integer In SSIS

May 20, 2015

I am trying to convert a string variable to integer in SSIS using the expression task.

@[User::Nummer] = (DT_I4) @[User::Name]

But I get an error that the conversion from (DT_WSTR) to (DT_I4) is not possible!!

View 2 Replies View Related

In Stored Proc - How Do I Find The Next Key Value (integer) And Use It To Populate A Field In The New Record.

Nov 27, 2006

Currently I have the following stored procedure which simply adds a new row in my SQL Express 2005. What I want is that -1). before inserting the record find out the new ID (primary key) value. (ID is automatically a sequential integer generated by SQL Server)2). and set COMPANY_ID = (new) ID Any thoughts? Thanks ALTER PROCEDURE usp_tbl_Company_Insert    @Company_ID int,    @Name varchar(200),    AS<FIND THE NEW ID of the new row in the database> @Company_ID = (new ID)  INSERT INTO tbl_Company (Company_ID, Name,)VALUES (@Company_ID, @Name) 

View 1 Replies View Related

Range On Time Field...

Sep 17, 2007

I want to create one complex query with Date time field,  my query is I want a grouping   between the time range
Â

EX:

Â

13/09/2007 1:00:00 PM    to  14/09/2007 4:00:00 AM    will be as Day1

14/09/2007 1:00:00 PM    to  15/09/2007 4:00:00 AM    Will be as Day2

''

''

''
This way the end date for the period will be 13/10/2007 4:00:00Â as Day 30

pavan

View 4 Replies View Related

How To Define A Range Of Values For A Field?

Oct 24, 2007

Hi everyone,

Primary platform is sql25k running with sp2.


I'd like to define for a concrete field which only could have three values:
"a","b","c"

TIA

View 7 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
End

Please help

View 6 Replies View Related

SQL Server 2012 :: Finding Longest String Within A String Field

Mar 20, 2014

We have some URLs within a bulk block of text some of which are very long. I need to identify rows where such urls exceed say 100 characters in length in amongst other text.So the rule would be return a record if within the string there is a string (without spaces) longer than 100 characters.

View 9 Replies View Related

Upper String Range Not Included In Between Statement

Jun 22, 2006

Hi There,
I have a column which contain alphanumeric values:
aab123add234cdf423dej553edg543
If I try to return records between these values 'a' and 'e' it will only go as far as d. (first letter)
aab123add234cdf423dej553
This is true if I use where value between a and e
Or if I use greater than equal to operators
Any help would be great.
Thanks
Stuart
 
 

View 2 Replies View Related

Strange Out Of Range Date In A Datetime Field

Sep 26, 2006

How is that I have stuff like...

13415-10-14 72:00:56.973

and -21858-02-28 390:54:27.200

in a datetime field when BOL says...

"Date and time data from January 1, 1753, through December 31, 9999, with an accuracy of three-hundredths of a second, or 3.33 milliseconds."

Not only that but I can't find where this field is getting written to in my trace

View 3 Replies View Related

Transact SQL :: Query DateTime Field By Date Range

Dec 2, 2015

I have a table of errors with a DateTime field for when the error occurred.  I want to query the table for a given date range omitting the time portion.  What is the most efficient way to perform this query?

View 5 Replies View Related

DB Design :: Convert Integer Date (MMDDYY) And Integer Time (HHMMSS) To DateTime Format?

Jul 20, 2015

Working on a new database where the Date and Time are stored in a Date Time Field.

Then working on an OLDER database file within the same SQL Database contains these 2 items as integers:

transDate = "71615" (July 16, 2015)
transTime = "12345" (01:23:45 AM)

How do we convert both of them into a single SQL DateTime field such as "2015-07-16 01:23:45.000" so that it can be used in a join restricting to a date time in a different SQL File that properly has the DateTime in it?

This works well for converting the transDate Part in the select statement:

   dbo.IntegerToDate(at.transDate) as transDate

   * That returns: "2015-07-16 00:00:00.000"

* The resulting data must work directly in a Microsoft SQL Server Management Studio Query using either using the "on" statement or part of the "where" clause. In other words, NOT as a stored procedure!

Also must be able to be used as a date difference calculation when comparing the 2 files Within say + or - 5 seconds.

View 3 Replies View Related

Transact SQL :: Convert Comma Separated String Values Into Integer Values

Jul 28, 2015

I have a string variable

string str1="1,2,3,4,5";

I have to use the above comma separated values into a SQL Search query whose datatype is integer. How would i do this Search query in the IN Operator of SQL Server. My query is :

declare @id varchar(50)
set @id= '3,4,6,7'
set @id=(select replace(@id,'''',''))-- in below select query Id is of Integer datatype
select *from ehsservice where id in(@id)

But this query throws following error message:

Conversion failed when converting the varchar value '3,4,6,7' to data type int.

View 4 Replies View Related

SQL 2012 :: Converting Time String In Temp Table To Military Time Then Cast As Integer?

Dec 26, 2014

I need to take a temporary table that has various times stored in a text field (4:30 pm, 11:00 am, 5:30 pm, etc.), convert it to miltary time then cast it as an integer with an update statement kind of like:

Update myTable set MovieTime = REPLACE(CONVERT(CHAR(5),GETDATE(),108), ':', '')

how this can be done while my temp table is in session?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved