Where Based On Length Of Field.
Oct 10, 2005Hey all.
I'm looking around for a solution on how to pull records back based on legnth.
So, if field A is more then 2 characters, return that row.
Thanks
Caden
Hey all.
I'm looking around for a solution on how to pull records back based on legnth.
So, if field A is more then 2 characters, return that row.
Thanks
Caden
I need to split a field based off it's length. Initial thought was to take Left(field, characters), and Right(field, characters), but now I see I am duplicating the data as I am capturing too much of the data in. However, what I actually need to achieve is in field1 capture the left 1000 characters, and in field 2 take from character 1001 to the end. How can I update my syntax so that field2 will ONLY capture from character 1001 to end?
field1 = COALESCE(CASE WHEN DATALENGTH(exitinterviewnotes) > 998 THEN LEFT(CAST(exitinterviewnotes AS VARCHAR(MAX)), 1000) ELSE exitinterviewnotes END,''),
field2 = COALESCE(CASE WHEN DATALENGTH(exitinterviewnotes) > 998 THEN RIGHT(CAST(exitinterviewnotes AS VARCHAR(MAX)), 1000) END,'')
I have a very strange situation. I've increased the size of an NVARCHAR field from 8 to 9 in a database table. The format of the data that I enter will either be an 8 character field (123456-8) or a 9 character field (1234567-9). The '-' is critical.
It used to only accept the 8 character version, but after increasing the field size, if I try to insert the 9 character field version, it gets truncated after the '-', as though it's still only allowing 8 characters. But that only occurs when I include the '-' or other such characters like '#'. If I try to insert 1234567a9, it works. The following explains the outcomes:
Inserted Value -> Result in table
123456-8 -> 123456-8 *Correct
1234567-9 -> 1234567- *Wrong
123456789 -> 123456789 *Correct
1234567#9 -> 1234567# *Wrong
1234567a9 -> 1234567a9 *Correct
Why is it that characters such as '-' and '#' are truncating the value, but only if the string is 9 chars long?
I'm currently using a direct t-sql insert statement in SQLExpress. The field is a simple NVARCHAR(9) field.
is there a property in the sql server where i can track the length of the value in a field.
Funnyfrog
Ok, so I've been struggling with the logic behind this one for a while, so I thought I'd ask you guys for some ideas :)
Basically, I have the following table structure
Employee(employee_number, continuous_start_date, ...)
The problem lies in working out a summary of service categories (0-6months, 7-12months, 13-24, 25+).
I can work out the length of service in months with the following code
SELECT DateDiff(mm, continuous_start_date, GetDate()) AS 'Service in months'
FROM employee
So the first stage is to summarise the length of service into groups as mentioned above.
Then the final stage is working out how many people are in each group!
Hope I have given enough information - and please do not post a full solution - just some hints on how to get the desired result ;)
Thanks later, and in advance :p
-GeorgeV
What is the max field length in SQL Server 7.0 that a varchar field can be?
I think 8000. Please advise
Thanks
Hi, can anyone tell me the best/easiest way to increase a field length in a table. We are using SQL 6.5
Regards
I have a text field and want to know if any of the text exceeds 10,000 characters
I can do a select max(len(rtrim(convert(varchar(8000)))) on the field but I'm not able to do for more than 8000 and you can't manipulate TEXT datay type.
Any ideas?
Thanks!
I have a database on sql2000. I want to change the length of a field in Table A, but it is related to another field in Table B. When I tried to change the length of the field in Table A via
ALTER TABLE table ALTER COLUMN field varchar(5).The query analyzer generates the following error.
Server: Msg 5074, Level 16, State 8, Line 1
The object 'UQ__table__77BFCB91' is dependent on column 'field'.
Server: Msg 4922, Level 16, State 1, Line 1
ALTER TABLE ALTER COLUMN field failed because one or more objects access this column.While when I tried the same query on the field in TABLE B, the query completed without any errors.
I'm sure it is possible to select all records where the length of a given field equals a certain value, but I don't know how to do it?
Can somebody tell me how?
Hans
There are two fieldsA1 nvarchar(30)A2 nvarchar(800)I know nvarchar field is alterable length, if I store a string mystring='abc' to A1 field or to A2 field, I think they use the same disk space, so I think it's always a good way to define a big length nvarchar field such as A3 nvarchar(4000) for any length string, becuase they always use the same disk space, is it right?
View 1 Replies View Relatedhai guys,
i want to find out the length of the varbinary field ex: 0x000003752B226B3D0579
thanks
hari
I need to expand the size of one column which has been defined as varchar(32) to varchar(50).Is this possible?Already there are many old records in the table,in what way it will effect the old records?Any help is appreciated.
Thanks!!
Hi, all
I am seting up a table with email message, I am wondering what is the max length for varchar field. I am so reluctant to use text field, since when
I run query for the descriptiona in sql analyzer, text field cannot be fully display in column. Any tricks to share?
Thanks
Betty
Hi,
If I want to make a field of characters to be unlimited length(or maybe 2k for example), what datatype should I use?
Char, varchar and text have a max. limit of 255...
Will appreciate any suggestions.
Thanks,
Nishi
I have to modify field length in the table, which is part of publication. I tried to use an Enterprise Mgr and received an error message because that table is scheduled for replication.
Is any way around this beside temporary stopping and restarting replication? And actually how to do this to be sure that after restart the data will be again in sync.
We have SQL Server 2000 Enterprise Edition and Windows 2000 Advanced Server.
How do I create a text file with fixed length fields from a SQL table using a stored procedure.
View 4 Replies View RelatedHi everyoneI had an access database running as the source for a website but ithas become too large to run correctly so it has been ported to MS-SQLthe problem is that 4 of the fields were Memo fields in access and assuch are 5000+ characters long each this overflows the allowed size onthe SQL server (8192)Is there a way round without splitting those 4 fields into seperatetales?? as this would cause a truly major re-write of the websiteThanks for any helpFurther details available if required
View 11 Replies View RelatedHow to get the max length of numeric field in a DataSet?
I have a DataSet bound to an Access database. Is it possible to get the maximum length of numeric field of a table in the DataSet? Many fields in the database tables have maximum length values set in ...
I have a table called BidItem which has another table calledBidAddendum related to it by foreign key. I have another table calledBidFolder which is related to both BidItem and BidAddendum, based on acolumn called RefId and one called Type, i.e. type 1 is a relationshipto BidItem and type 2 is a relationship to BidAddendum.Is there any way to specify a foreign key that will allow for thedifferent types indicating which table the relationship should existon? Or do I have to have two separate tables with identical columns(and remove the type column) ?? I would prefer not to have multipleidentical tables.
View 26 Replies View RelatedI know there has to be a way to do this, but I've gone brain dead. Thescenario..a varchar field in a table contains a date range (i.e. June 1,2004 - June 15, 2004 or September 1, 2004 - September 30, 2004 or...). Theusers have decided thats a bad way to do this (!) so they want to split thatfield into two new fields. Everything before the space/dash ( -) goes intoa 'FromDate' field, everything after the dash/space goes into the 'ToDate'field. I've played around with STRING commands, but haven't stumbled on ityet. Any help at all would be appreciated! DTS?
View 1 Replies View RelatedI have a few columns in table with default value defined as zero length string (''). I want to insert record from DetailsView which uses SqlDataSource as DataSource. In the ItemInserting event, if the data is not valid, I want to use zero length string for the column. But I always get Null instead of zero length string. The code in ItemInserting event looks like this:
If objddl.SelectedIndex > 0 Then e.Values("myFld") = objddl.SelectedItem.ValueElse e.Values("myFld") = ""End If
The line: e.Values("myFld") = "" put Null in the column.
How can I set a column as zero length string using the SqlDataSource?
Any help is appreciated.
Thanks.
Hi,
I have to export data from a database in a special form (the customer wants it this way): every record in one line, and all fields in a large string. Thus, only by convendion it is defined the first seven characters being the central number, the next fivr characters the number of this spare part type, the following 30 the description, and so on...
Just at the end of every record has to be CF-LF.
all works well so far by with this code (in PHP) -
except one thing - see details below the code snippet):
$q1 = "SELECT dirc_matdata.* FROM dirc_vorgang, dirc_matdata ";
$q2 = "WHERE dirc_vorgang.rep_out> '".$anf_dat."'";
$q3 = "AND dirc_vorgang.rep_out < '".$end_dat."'";
$q4 = "AND dirc_matdaten.auftrags_nr = dirc_vorgang.auftrags_nr";
$q5 = "INTO outfile '".$drive.":/matdata.dat'";
$q6 = "FIELDS TERMINATED BY '' LINES TERMINATED BY '
';";
$query = $q1.' '.$q2.' '.$q3.' '.$q4.' '.$q5.' '.$q6;
The INT (integer) fields appear in the (plain text) output file with wrong field lengths. Although I had set the first field (i.e. the number of this type ofparts) to a length of 5, this field appears in the outfile being 10 characters long -- the maximum length of a normal INT type field (and twice as long as it should be).
Or (when set to filed type "MEDIUMINT"), it appears in the length of 8 characters only. But I need this data exactly 5 characters long in this application.
BIG QUESTION: How can I make mySQL (Ver. 4.1) write this fields into the outfile with their correct length as defined in the database structure?
Is this flaw already known in the community?
Is there any sort of "workaround"?
Thank you for every hint!
-ah-
Hello,
I am running a stored procedure thru' isql.
This returns only one field.
The sp is executed fine but if the data has length greater than 255 the data is truncated.
How do u capture the full output ?
Thanks In Advance
Ashutosh
:rolleyes:
Hi,
I am trying to upload a fixed field text file to a sqlserver table using the DTS wizard. The txt file has 111 columns and the total length of a single row is 5897. The problem is when I use the wizard to specify the starting and ending of each column, its not allowing me to specify the columns beyond the position 4095.
Is there a limitation on this? if so is there a work around ? to solve this.
Any help on this is truly appreciated.
Thanks much. :)
Hi
I have two databases that are merged using replication, and I want to change the length of one of the fields. Can anyone think of a way of doing it that doesn't require dropping the whole publication and rebuilding it? Thanks Ed
I have a field Char(10) named bank, and another one Char(15) named namebank.
I need to create a TSQL query, but i need to preserve the white space on my first field named bank and concatenate with the other namebank, this last i dont need white space.
B001 Bank 123
How can accomplish this query.
Hi Everyone,I have a question about dynamically changing the length of a varchar(n)field, in case the value I'm trying to insert is too big and will givea "truncated" error, but before the error is given! i.e. Is there somekind of a way to "test" the length of the field while Inserting thevalue into it, and to have it automatically increase its length to thelength of the value being inserted, in case the value is too big?I've been able to do this in a "primitive" way, simply by identifyingthe specific error number in case the value is being truncated, andthen increasing the length of the varchar(n) field by using the ALTERcommand, and then duplicating the insert statement, but is there astandard (shorter) way of doing this?Here is my code (I'm working in an ASP environment):<%var_txt = "abcdefghijklmnopqrstuvwxyz12345678789"sql = "Insert Into Table1 (text) Values ('" & var_txt & "')"On Error Resume Nextconn.Execute sqlIf err = -2147217833 ThenResponse.Write "Error Recognized Successfully!<br /><br />"sql = "ALTER TABLE Table1 ALTER COLUMN text VARCHAR(" &Len(var_txt) &") NOT NULL"On Error Resume Nextconn.Execute sqlIf err<>0 ThenResponse.Write "Error while trying to alter Column:<br/>" & err & "= " & err.description & "<br />"ElseResponse.Write "Column altered successfully to: " &Len(var_txt) &"<br />"sql = "Insert Into Table1 (text) Values ('" & var_txt &"')"On Error Resume Nextconn.Execute sqlIf err<>0 ThenResponse.Write "<br />Error number 2:<br />" &err.description &"<br />"ElseResponse.Write "Now it was added successfully!HaHa!<br />"End IfEnd IfElseResponse.Write "Success."End If%>Thanks in advance!
View 2 Replies View RelatedHow to limit the length of a database field such that only first 12 characters are shown in the result?
For example, I have show the only first 12 characters of employee name.
To simulate problem do follows:
1. Add Script source component.
2. Add 2 string output collumns: F1 length 50, F2 length 110
3. Add Union All component connected to Script source component
4. Add Script transformation component connected to Union All component
5. Mark F1 and F2 as input collumns
6. In the Input and Output section of the script transformation component check that length of the fields is 50 and 110 correspondingly
7. Edit Union All component: change Union All Input 1 to <ignore> for Output collumns F1, and F2; change Union All Input 1 to F2 for F1 and F1 for F2; change back <ignore> for F1, <ignore> for F2; set back F1 for F1, F2 for F2; Click OK to save
8. In the Input and Output section of the script transformation component check that length of the both fields is 110 now.
So, be careful to select output columns values in Union All component. If you choose wrong field by accident, and replaced it with correct one straight away, the length of output column could be stored not as you expect an need.
Hi All,
Is there a way to check the data type and the maximum length of a field?
is there any way or a tool to identify if in procedure the Parameter length was declarated less than table Column length ..
I have a table
CREATE TABLE TEST001 (KeyName Varchar(100) ) a procedure
CREATE PROCEDURE SpFindNames ( @KeyName VARCHAR(40) )
AS
BEGIN
SELECT KeyName FROM TEST001
WHERE KeyName = @KeyName
END
KeyName = @KeyName
Here table Column with 100 char length "KeyName" was compared with SP parameter "@KeyName" with length 40 char ..
IS there any way to find out all such usage on the ALL Procedures in the Database ?
For those of you who would like to reference my exact issue, I'm dealing with the RSExecution SSIS package at the "Update Parameters" data flow task, at the Script Component.
The script tries to split parameter data into name and value. Unfortunately, I have several reports that are passing parameters that are very large. One example has over 65,000 characters all in the normal "¶mname=value&parm2=value..." format.
The code in the script works fine until it gets to one of these very large parameter sets. I have figured out what is causing the issue. Here's some code:
Dim paramBlob as Byte()
paramBlob = Row.BlobColumn.GetBlobData(0, Row.BlobColumn.Length)
The second parameter of the .GetBlobData function takes an INTEGER as its count! Therefore, no matter what kind of datatype I pass to the string that the script will later split, it will be limited to 32767 characters.
THIS IS A PROBLEM!!!
Does anyone know a workaround for this issue? I need all of the parameter data to be reported, and I would hate to have to skip over rows like this. Also, if I'm missing something, please fill me in!
Thanks for your help in advance,
LOSTlover