Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
shifis
Posting Yak Master
157 Posts |
Posted - 2006-03-29 : 20:19:05
|
| I did an sp, that do the rpad function, but I want to used has I used a Oracle function in the select statement select SP_RPAD empname,20,'w' as nombre from tbejand it sent me an error:Invalid column name 'SP_RPAD'.How can I do cretate a function that I can call from a select statement?--Hace la funcion del RPAD, rellena a la derecha con el caracter que le-- mandemos hasta que la cadena tenga la longitud que enviamos--@Cadena--@Char_llenar--@LongCadenaCREATE PROCEDURE SP_RPAD @Cadena varchar(200), --Cadena Original a la que se va a rellenar@LongCadena int, --Longuitud final que tendra la cadea@Char_llenar char(1) --Caracter con el que se va a rellenarASSELECT RIGHT(REPLICATE(@Char_llenar,@LongCadena) + @Cadena ,@LongCadena) AS RPADGO |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-03-29 : 20:25:59
|
SP_RPAD is a stored procedure.You execute the stored procedure this wayexec SP_RPAD 'empname', '20', 'w' Looking at your select statementquote: select SP_RPAD empname,20,'w' as nombre from tbej
you should be creating a function instead.CREATE FUNCTION F_RPAD( @Cadena varchar(200), --Cadena Original a la que se va a rellenar @LongCadena int, --Longuitud final que tendra la cadea @Char_llenar char(1) --Caracter con el que se va a rellenar)RETURNS VARCHAR(200)ASBEGIN RETURN (RIGHT(REPLICATE(@Char_llenar,@LongCadena) + @Cadena ,@LongCadena))END and then you can call your function likeSELECT dbo.F_RPAD(empname, 20, 'w') as nombreFROM tbej KHChoice is an illusion, created between those with power, and those without.Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant |
 |
|
|
shifis
Posting Yak Master
157 Posts |
Posted - 2006-03-29 : 21:26:42
|
| Thanks!!!That's what I was looking for!! |
 |
|
|
|
|
|
|
|