Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strings

Status
Not open for further replies.

lasd

Programmer
Jan 14, 2005
48
0
0
IE
Hi

Another question. I have a value in my table employees for eg. sender=15...... so this value is referenced by employees.sender...... for another column in my sql i want to add in 00 before the 15. How do i do this.
i want the last column to have for eg
0015
0031
0051

instead of

15
31
51

thanks for the help
lasd
 
SELECT '00' || sender FROM employees

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 

Which DBMS?

For T-SQL:
Select '00'+sender from employees;
-- or --
Select RIGHT('0000'+sender,4) from employees;

Others:

Select CONCAT('00',sender) from employees;

[noevil]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
There's no need to ask for dbms since this is the ANSI SQL forum. I suppose lasd is expecting an ANSI compliant solution, just like PHV's answer.
 

Actually the ANSI SQL would be: CONCAT() [shadeshappy]

----------------------------------------------------------------------------
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
 
The ANSI SQL function is CONCAT()
The ANSI SQL operator is ||

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Sorry for being such a smartass, but CONCAT is not an ANSI SQL function.

ISO/IEC 9075-2:2003 (E):
"4.2.3 Operations involving character strings
4.2.3.1 Operators that operate on character strings and return character strings
<concatenation operator>is an operator,||,that returns the character string made by joining its character
string operands in the order given."

The word CONCAT isn't mentioned in the standard specification.
 
the trouble with the SQL Standard is that you have to spend a couple hunnert bucks if you want to know what's in it



r937.com | rudy.ca
 
Yeah, I know. Pretty stupid to charge that much if people are supposed to use the standard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top