Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MS SQL Server


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





No TRIM Function In 2005 - Are You Serious!?


I cannot believe that there is yet another version of SQL Server without a TRIM function.  So for SQL 2005 (like I've done in 7.0 and 2000) my T-SQL will look like dog poo because I will have to write LTRIM(RTRIM(MyValue)) anytime I want to remove whitespace from both ends of character values instead of just writing TRIM(MyValue).




View Complete Forum Thread with Replies

Related Forum Messages:
I Couldn't Find TRIM Function
Hi,

I found rtrim and ltrim functions, but I didn't find trim, so should I use rtrim(ltrim('  a ' ))? Am I right?

cheers,

Alessandro Camargo

View Replies !
ROW_NUMBER() Function Is Not Recognized In Store Procedure.(how To Add ROW_NUMBER() Function Into SQL SERVER 2005 DataBase Library )
Can anybody know ,how can we add  builtin functions(ROW_NUMBER()) of Sql Server 2005  into database library.
I get this error when i used into storeprocedure :
ROW_NUMBER() function is not recognized in store procedure.
i used MS SQL SERVER 2005 , so i think "ROW_FUNCTION()" is not in MS SQL SERVER 2005 database library.
I need to add that function into MS SQL SERVER 2005 database library.
Can anbody know how we can add that function into MS SQL SERVER 2005 database library?
 

View Replies !
Trim() In T-sql?
is there a function trimming string such as Trim in vb?

View Replies !
How To TRIM
Hi I have the below paragraph in my datacolum called 'Description'

Ansmann Powerline 5 Super Fast Charger, Microprocessor controlled desktop charger with discharge function for up to 5 NiCd/NiMH cells, For all NiCd and NiMH rechargable batteries including AA/AAA/C/D/9V, Negative Delta V control, faulty cell detection, defined predischarge, trickle charge, separate status indicator for every charging slot, ultra rapid charging, 230V AC. For UK use. Price for 1 Charger.

How do I take only the sentence upto the first comma in my STORED procedure

(ex:Ansmann Powerline 5 Super Fast Charger)

Advance thanks

Vaishu

View Replies !
Trim()
Okay basic question from the village idiot. How do I return only the date and not the time from a datetime column and also can I return only a set number of digits in a float column?

Thanks in advance peter

The Yak Village Idiot

View Replies !
Help Trim Or Len
Guys/Girls

Have a small problem I have received a load of data in a flat file format and each column has dividend up with a comma. I have stuck the whole row in to its own column.

What I want to do is take the first 12 characters of the row and put them in there own column.

I think I need to use the Len function or the trim function, so can some body point me in the right direction on how to do this.

Regards Lee

View Replies !
(((Trim(Nz
IN ACCESS
UPDATE 14_Together_final_ICNs INNER JOIN 14_Together_UniqueSKUs ON [14_Together_final_ICNs].SKU = [14_Together_UniqueSKUs].SKU SET [14_Together_final_ICNs].sku_desc = [14_Together_UniqueSKUs].NewDesc
WHERE (((Trim(Nz([NewDesc])))<>""));



THIS IS WHAT I TRY IN SQL SEVER BUT GET A DIFFERNET RESULT

UPDATE [14_Together_final_ICNs]
SET sku_desc = [14_Together_UniqueSKUs].NewDesc
FROM [14_Together_final_ICNs] INNER JOIN
[14_Together_UniqueSKUs] ON [14_Together_final_ICNs].SKU = [14_Together_UniqueSKUs].SKU
WHERE (RTRIM(LTRIM([14_Together_final_ICNs].sku_desc))<> N'')

View Replies !
Trim To Space
What is the best way to trim a string to the space in a select statement? An example string would be:
'asdf and hjkl'

The result would be:
'asdf'

View Replies !
Left Trim
What is the syntax of left triming characters seperated by space.

e.g elsie reed
and i want elsie to go to one field and reed in another field i do not want to use numbers because they don't all have the same numbers but are all seperated by spaces

View Replies !
Trim An Apostrophe Off Of A Last Name
we need to cut the aprostrophe out of a name (ie...o'brien, o'leary) to create userid's... can this be done....thanks!

View Replies !
How To Trim A Field Value In Rss
can any one explain how to trim a value  on bothside in rss

 

for eg:

'asd          '

 

'                     asd'

i wanna   this output    'asd'............

 

 

can i give this command

                   =Format(Fields!company.Value.Trim)

 

 

 

View Replies !
Trim String
 

In my report, i  have a TextBox which retrieve the result from the database.I am using this code :

 
=Fields!Category.Value.ToString().Trim(" ").TrimEnd(",").TrimStart(",")
 
But i am encountering a problem,wherein,when the value contains '&' (ex. Jog & Hop)
the result became Jog&amp;Hop.
What could be wrong with my trim???
Thanks!!

View Replies !
T-SQL TRIM() Error
 

Whan using the TRIM() function in a SELECT we are getting an invalid function error.  What gives?  I thought TRIM() was T-SQL & not one of Microsoft's  SQL "extras".

 
Thanks!

View Replies !
TRIM Question?
"select RTrim(columName) from tableName"

  it  can change the stirng "   abc"  to "abc". But I want  change the string "a  bc" to "abc".

Why the  TRIM  cannot work  ?

How do I  do ?Thanks.

View Replies !
Trim Character
OK, the problem is like this; say the table is sumthing like this

i have a table 't3' has 3 fields
id(number,2)
date(date/time)
text(varchar,200)

eg. id date text
-----------------------
01 05-jul-07 abcdefghijkl (i want to get rid of the first 6 characters i.e. abcdef)

i want to display 'text' field from t3 table but with the first 6 characters trimmed/removed (i want to get rid of the 6 first characters)

so i did:

select LTRIM(text,6) from t3

but the above code didn't work because LTRIM only trims spaces NOT characters... Is there any way that i can trim off the first 6 characters from every record in the 'text' field?

View Replies !
UPDATE Using TRIM
hi guys,

i need to update a column by trimming the right end. i tried many things but its not working. can anyone tell me?

Regards,
David

View Replies !
Trim Space From Some Fields
I have a table with a keyword field. In this keyword field some of the entries have a space before the word and some don't.
How can I remove all of the spaces from the fields that have them and not trim from the ones that don't.

View Replies !
Trim Zero Out (007500,190000)
hi I have this field

invoice#
007500
190000
000080

I need to run a query to trim the left zeros out and have the following output

invoice#
7500
190000
80

how can I do that in sql select ... or with update table set invoice#=..??
Thanks for your help
Al

View Replies !
Optimize & Trim Query
I’m trying to optimize the following view so that it runs faster and to trim the code where possible. It runs for 1:57mins. Is that good or it can run much faster than that? Where do l start? It’s a view for a report. Please help l’m running on SQL 2000

CREATE View SalesTest AS
SELECT dbo.Loan.loan_No AS [Loan No], dbo.Customer.customer_No AS [Customer No], dbo.Customer.first_Name + ' ' + dbo.Customer.surname AS Customer,
dbo.Employer.employer_Name AS [Employer Name], dbo.Loan.store AS [Store No], dbo.Store.store_Name AS Store,
dbo.Region.region_Description AS Region, dbo.Financier.financier_Short + dbo.Term.term_Description AS Product,
dbo.Loan.date_Issued AS [Transaction Date], dbo.Loan.capital_Amount AS [Capital Amount], dbo.Loan.interest_Amount AS [Interest Amount],
dbo.Loan.interim_Interest_Amount AS [Interim Interest Amount], dbo.Loan.interest_Amount + dbo.Loan.interim_Interest_Amount AS [Interest2 Amount],
dbo.Loan.insurance_Amount AS [Insurance Amount], dbo.Loan.admin_Fee AS [Admin Fee], dbo.Loan.total_Amount AS [Total Amount],
dbo.Loan_Type.loan_Type_Description AS [Loan Type Description], dbo.Loan.user_Changed AS [User], dbo.Loan.first_Payment AS [First Payment],
dbo.Loan.monthly_Payment AS [Monthly Payment], dbo.Loan.repayment_Period AS [Repayment Period],
dbo.Loan.outstanding_Amount AS [Outstanding Amount], dbo.Loan.last_Payment_Date AS [Last Payment Date],
dbo.Status.status_Description AS Status, CONVERT(Char(3), dbo.Loan.loan_No, 1) AS Company, dbo.Customer.physical_Address1 AS Mine1,
dbo.Customer.physical_Address2 AS Mine2, dbo.Customer.physical_Address3 AS Mine3, dbo.Loan.maturity_Date AS [Maturity Date],
dbo.Agent.agent_Short AS Agent, dbo.Financier.financier_Short AS Financier, dbo.Loan.product AS [Loan Product],
dbo.Deduction_Detail.teba_Account_No AS [Teba Account No]
FROM dbo.Loan INNER JOIN
dbo.Customer ON dbo.Customer.customer_No = dbo.Loan.customer_No INNER JOIN
dbo.Status ON dbo.Status.status = dbo.Loan.status INNER JOIN
dbo.Store ON dbo.Store.store = dbo.Loan.store INNER JOIN
dbo.Product ON dbo.Product.product = dbo.Loan.product INNER JOIN
dbo.Product_Type ON dbo.Product_Type.product_Type = dbo.Product.product_Type INNER JOIN
dbo.Financier ON dbo.Financier.financier = dbo.Product_Type.financier INNER JOIN
dbo.Term ON dbo.Term.term = dbo.Product.term INNER JOIN
dbo.Employer ON dbo.Employer.employer = dbo.Customer.employer INNER JOIN
dbo.Region ON dbo.Region.region = dbo.Store.region INNER JOIN
dbo.Loan_Type ON dbo.Loan_Type.loan_Type = dbo.Product_Type.loan_Type INNER JOIN
dbo.Agent ON dbo.Agent.agent = dbo.Product_Type.agent INNER JOIN
dbo.Deduction_Detail ON dbo.Loan.customer_No = dbo.Deduction_Detail.customer_No AND
dbo.Loan.deduction_No = dbo.Deduction_Detail.deduction_No
WHERE (dbo.Loan.outstanding_Amount <> 0)

View Replies !
Trim Blanks From Name Field
Can someone help me with this little problem ?

I have a table that has first & last name fields. They're each 20 bytes long. I would like to remove the trailing blanks from the fields and have just null following the data .. Is that possible ? Then when I send the file to someone, they won't have to strip out blanks when combining the names together.

OR 2nd choice ... Create a temporary work file and copy the data without trailing blanks to the new work file.

I've looked at RTRIM, but can't seem to get it right.

Thanks for any help.

View Replies !
Replace And Trim Statement
I have a SQL table which has field data like below

field a field b
123 KB 246 kb

How can I strip out just the numbers(there will always be a space between the number and KB?
Thanks

View Replies !
Can You Trim In The Middle Of A Join?
Is it possible to use a TRIM(){or similar} function when JOINing 2 tables via a NVARCHAR field in T-SQL?

I need to trim the field first because some of the data contains trailing spaces (GRRR) and so might future data...

View Replies !
TRIM + Dynamic Expression
This is a very weird issue, and I can't seem to pinpoint the actual cause. I have a dynamic expression for Excel files that gets evaluated at run-time. One of the parameters for creating this path is pulled from the database - the column is nvarchar(10) and most of the values are only 2-characters long. I have tried LTRIM(RTRIM()) inside SQL Server as well as TRIM() in SSIS's Expression Editor, but nothing seems to work. At run-time the package fails, and the error I receive is because the value that gets pulled from the DB has trailing spaces. What's even annoying is the package runs fine on my XP machine, but fails on a W2K3 box - both setups are using the same back-end database.

Is this is a bug, or am I just screwing up something unknowingly? Thanks.

View Replies !
EASY! Trim String?
I have values in a matrix takin too much space. Since they are just used as the matrix column header, cant i trim it or something. To display just the first 3 letters of the the attribute, and not the whole string? Whats the code for that?

=Fields!Collision_Type.Value   thats my field right now.

 

Please help! thanks!

View Replies !
Trim Leading Zeros
My records are like this.
Col1
-----
00001
03456
00577
05011
00099
01090
 
I want to remove the zeros on the left and the answer should be like this.
 
Col1
-----
1
3456
577
5011
99
1090
 
How to trim the leading zeros.
Thanks.
 

View Replies !
How To Trim Off Space In A String
str1 has some space in front of it and after it.
trim(str1) does not seem to work.
what is the right syntax for that?
Thanks

View Replies !
Trim Spaces In Middle
In a table I have a coulmn of postal-codes where there is a space in the middle of the postcode. How do I do to trim them away?

View Replies !
Trim Data From Left And Right
Guys,
I need to cleanup a query on Item Numbers.
I don't want to edit the data... just display it clean.

I want to show ItemNumbers without any 'S' on the left, and without any '501' or '601' on the right.

What do you think is my best bet fot getting this?
I was thinking about using TRIM, but maybe that's just for whitespace.

View Replies !
Trim On Bulk Insert
For a bulk insert is there a way to trim the data that comes in with a fixed length of say 45 characters but only 14 used and the rest is all spaces?

View Replies !
Need SQL Help - Trim Parentheses In Column Of Data
Hi All, I am sure someone has done this before. Trying to write a SQL statement to UPDATE a column named Prod_Model. The table name is tbl_MASTER. Wanting to trim the parentheses out of the data and update back to the table.  Any help on the SQL statement?

View Replies !
Trim Large Output Parameter Value?
I am returning a field from a db using an OUTPUT parameter that looks like this in the stored procedure...
@theOutputParam varChar(4000)
When it is returned to my VB.NET code it looks like this...
Dim theString as String = [theSQL parameter]
... When I run and debug and look at...
theString.Length
...it returns 4000 instead of only the actual characters that are entered into the field.  So, if the field value is "FOO" I get "FOO" plus 3997 blank characters. 
So, I've tried....
theString = trim(theString)
But, I still get 4000 characters.  I'm dunno what else to try, do you?
Thanks in advance for any assistance...
Bernie

View Replies !
Trim And Update Not Working As Expected
I was hoping that the Trim function inside the update command, cmdUpdate.Parameters.Add("@doc_num", Trim(txtDocNum.Text))
, would deal with any leading and trailing spaces, but it does not seem
to be doing anything at all. The value from the textbox still arrives
in the database table with leading spaces!!

Am I doing something wrong?

View Replies !
Is It Possible To Trim The Columns In Select Statement
Can you please tell me, is it possible to Trim the columns in a select statement:


select eventid,referenceno,EventDesciption,modulename,moduleid,created_by,CONVERT(varchar(10),eventdate,101) as eventdate from MYTable

Thank you very much.

View Replies !
Using A Convert And Trim Statement Combined
I need t do some date converts on some varchar fields which
might have trailing spaces.
I tried this below but still

select df_ppd, df_xray_date from patient_
where convert(datetime,rtrim(df_ppd),101) > '06/20/2000'

received a conversion error message

Server: Msg 242, Level 16, State 3, Line 4
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

Any ideas?

View Replies !
Trim Trailing White Spaces
Hi All,

I have a column which has some white spaces that I suspect is tab delimeted one. So when I use a rtrim(col1) it would not trim those. So i used a scrip component and wrote this line,

Row.trimDetail = RTrim(Row.detail)

here trimdetail is an o/p column and detail is the input col with the trailing spaces.

but still I don know why the column has that spaces. Can someone help me to figure out what is the problem ?

Thanks in advance,

View Replies !
How To Trim Spaces In The Query Result
 

Hello guys,
 
Iam showing the query results in the asp.net grid. Iam getting a long string with more than 1 space between some words.
How i can trim the spaces of that column result.
 
I tried RTRIM and LTRIM but these functions need two individual strings with spaces either left or right.
 
Help me.

View Replies !
Trim Leading Zeros From A Varchar Column?
 My table has a column named [Liability] varchar datatype which has the data in the format
(
3535.00,
00393.99,
00Loan,
0.00,
.00
*.00
)
 
I want to trim the leading zeros so that the output should be(trim only the leading zeros)
(
3535.00,
393.99,
Loan,
0.00,
.00
*.00
)
 
Can someone show my the sql statement for this?
 
Thanks.

View Replies !
Trim Functions With DateTime Field Types
I used a Ltrim(RTrim) function for a datatype and it transforms the
date from '2001-04-05 07:39:31.017' to 'Apr 5 2001 7:39AM'.
When I used the trim functions as part of a create view statement it converts the datatype to varchar(40).
When I select the Datetime column for the view that I used the trim function on a datetime datatype field in Query Analyzer it displays the column as being 8000 characters long.
I'm not sure why it is doing this?
sp_help shows the column as varchar(40)?

View Replies !
How To Trim Leading Zeros From A Varchar Column?
My table has a column named [Liability] varchar datatype which has the data in the format
(
3535.00,
00393.99,
00Loan,
0.00,
.00
*.00
)
 
I want to trim the leading zeros so that the output should be(trim only the leading zeros)
(
3535.00,
393.99,
Loan,
0.00,
.00
*.00
)

 
Can someone show my the sql statement for this?
 
Thanks.

View Replies !
Proc To Trim Leading/trailing Spaces-all Char Cols
I have found this useful when importing certain text files into a staging table prior to appending main tables, and when it is typical that many of the imported text columns are padded with leading or trailing spaces.

Naturally, this can also be handled in VBScript processes during DTS as part of the import steps...but still...this comes in handy at times.

Passing a table name to the proc builds an Update statment to update the table char/varchar/nvarchar/nchar type columns with a trim statement.

Not sure if it can be done without a cursor..but it is effective

Works in both 2000/2005

It is most beneficial for leading spaces and for the char type column.



SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE Proc [dbo].[pTrimCharacterFields](@TableName varchar(100))
As
DECLARE @SQLstring varchar(8000)
DECLARE @firstTime bit


-- Start building our UPDATE statement
SELECT @SQLstring = 'UPDATE ' + @TableName +' SET '
SELECT @firstTime = 1

-- Get a list of character columns in this table
DECLARE getColumnsCursor CURSOR
READ_ONLY
FOR
SELECT c.COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS c
WHERE c.TABLE_SCHEMA = 'dbo' AND
c.TABLE_NAME = @TableName AND
c.DATA_TYPE IN ('char', 'nchar', 'varchar', 'nvarchar')
ORDER BY c.COLUMN_NAME

DECLARE @columnName nvarchar(128)
OPEN getColumnsCursor

FETCH NEXT FROM getColumnsCursor INTO @columnName
WHILE (@@FETCH_STATUS <> -1)
BEGIN
IF (@@FETCH_STATUS <> -2)
BEGIN
IF (@firstTime = 0)
SELECT @SQLstring = @SQLstring + ','

-- append our column to the UPDATE statement
SELECT @SQLstring = @SQLstring + '[' + @columnName + ']=LTRIM(RTRIM([' + @columnName + ']))'

SELECT @firstTime = 0
END
FETCH NEXT FROM getColumnsCursor INTO @columnName
END

CLOSE getColumnsCursor
DEALLOCATE getColumnsCursor

EXEC(@SQLstring)
GO

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO


Here is a test of it.

Create Table TrimTest (ColumnA char(10) not null,
ColumnB nvarchar(10) not null,
ColumnC varchar(10) not null,
ColumnD nchar(10) not null)

Insert Into TrimTest(ColumnA,ColumnB,ColumnC, ColumnD)
Select ' TestA ', ' Test B ', ' TestC ', 'A 1 '

SelectColumnA,Len(ColumnA) as LenA,
ColumnB, Len(ColumnB) as LenB,
ColumnC,len(ColumnC) as LenC,
ColumnD,len(ColumnD) as LenD
FROM TrimTest

Exec dbo.pTrimCharacterFields 'TrimTest'

Select ColumnA,Len(ColumnA) as LenA,
ColumnB, Len(ColumnB) as LenB,
ColumnC,len(ColumnC) as LenC,
ColumnD,len(ColumnD) as LenD
FROM TrimTest
Drop Table TrimTest



Poor planning on your part does not constitute an emergency on my part.

View Replies !
Trim Or Ignore Extra Carriage Returns For Flat File Source
the incoming txt has some extra carriage returns.  How can I tell the flat file Source component to just ignore or trim those....because the component fails when it comes across them.

Example, the txt file has:
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd
----get rid of this blank line or else my component fails! ----
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd
 
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd
asdfsf,dfdfd,dfdfd,dfdf,dfdfd,fdfd



 

View Replies !
Split Function - Sql Server 2005
In my table, column1 having a comma separated values.I want to display in rowwise.
for example:
column1
aa,ss,ff
 
output should be
aa
ss
ff
 
Pls. help me..I want to do thr query.

View Replies !
Can A Sql 2005 Function Return More Than A Variable
Hi,I have a sql 2005 function who return a distance from 2 zipcodes. This function is called from a Stored procedure like this :SELECT *, dbo.fn_GetDistance (...) AS DistanceIn this function, i have a Latitude and i want this Latitude to be also returned.It is possible or a function can return only one variable?If it is possible, what's the syntax of it?Thanks in advance

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved