![]() |
|
![]() | ||
|
Subject:
SQL programming
Category: Computers > Programming Asked by: sea2see-ga List Price: $2.00 |
Posted:
13 Jan 2003 10:57 PST
Expires: 12 Feb 2003 10:57 PST Question ID: 142106 |
when doing a sql query, I would like to remove all trailing spaces from a column name. I know there is an "rtrim" command taht can do this, but when I do a "select rtrim(column name) from table, it won't work! When I set a declare statement, declare @name varchar and then do "select rtrim@name=(column name) from table it doesn't work either. I think I have to do a select column name from table, then convert column name to string data, but I don't know how to do this. I need this to print some columns from the table, but the column that has the name in it needs to be shorten to character length of ht name only! Thanks... |
![]() | ||
|
There is no answer at this time. |
![]() | ||
|
Subject:
Re: SQL programming
From: vballguy-ga on 13 Jan 2003 11:23 PST |
RTrim should be the correct command and your syntax looks correct. "select RTRIM(col name)". Some questions that might help: Can you tell us what the datatype is for the column that you want to trim? What RDBMS (ie MS SQL Server, Access, etc) are you using? How are you checking that RTRIM is not working - Maybe your query tool is adding the extra spaces? |
Subject:
Re: SQL programming
From: sea2see-ga on 13 Jan 2003 12:06 PST |
The datatype for the column name I am trying to rtrim is varchar(63). I am running on a sybase server. Thanks... |
Subject:
Re: SQL programming
From: bio-ga on 13 Jan 2003 12:55 PST |
Hi, As soon as I know you don't need rtrim for varchar fields since they are already trimmed when selected. There might be another problem. |
Subject:
Re: SQL programming
From: sea2see-ga on 13 Jan 2003 13:19 PST |
Defining the datatype as varchar(63), simply allows for names up to 63 characters long. If the name is less 63 characters it is padded with spaces. When I run an sql program and pipe the output to a file the name field leaves a gap between it and the next field I am selecting as I have very few, if any, names the are 63 characters long. |
Subject:
Re: SQL programming
From: vballguy-ga on 13 Jan 2003 14:36 PST |
I believe the problem is coming from your query utility. Either ISQL or whatever you are using is trying to create an output file with a fixed length format. When you generate an output file, you need to be able to tell one one field ends and the next one begins. There are two ways to do this. The first is to make every record (line) use the same number of characters. (spaces are added to the end of fields that are to short) or to use a delimiter between fields. Some programs put strings into double quotes, or use the "|". If your output file does not have some sort of way of denoting the start and stop location of the string, then this is almost definitly your problem. If you are using ISQL I would recomend looking at isql -? (or it might be just isql ?) for help about field delimiters. |
Subject:
Re: SQL programming
From: sea2see-ga on 13 Jan 2003 15:23 PST |
I am using the command line in a DOS cmd prompt (able to connect to DB through a sybase client insatlled on my desktop) "isql -U(username) -P(password) -i(sql program name) >>(output file name); this requires no output formating provisions. Likewise the code to extract the fields I need is: select default_name, obj_ip_addr1, obj_ip_addr2, obj_ip_addr3, obj_ip_addr4 from column_name where obj_ip_addr1=xxx and obj_ip_addr2=yyy and obj_ip_addr3=zzz and temp_id<>32 and alloc_type_cd=9 go This code extracts the column name and the column data. The ability to exclude the space padding would, from everything I can see, have to occur at the select statement as there is not any cerebral code going on! |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |