Does anyone know a function in SQL or how I can get the amount of characters of a field?
I have a column named NU_IPS wich contains data varchar type, that has a % symbol at the end, like 9.7% and so on... But in original table it can't be like this (it has to bem float type), I just want the number content, like this 9.7 For that I need in DTS put a query that convert it. That's why I need a function or something that can get the quantity of characters of each field.
So, It would be someting like this...
select substring(convert(varchar(getSizeField() - 1), nu_ipi), 1, 4) from dbo.t_STAGEAREACHAIR
It would cut always the last caracter, wich is '%'...
Any clues?
All posts are welcome, thanks.Look up the Len() - function ...|||Thanks Nephilim!
But why can't I put this function in the convert if it returns a int type?
I guess it can't process each field at time, 'cause we can admit there's a table in convert varchar paremeter, it's obvious.
Like:
select substring(convert(varchar(SELECT len(nu_ipi) - 1 FROM dbo.t_STAGEAREACHAIR), nu_ipi), 1, 4) from dbo.t_STAGEAREACHAIR
I've tried putting an IF statment...
Like:
if ((select len(nu_ipi) - 1 from dbo.t_STAGEAREACHAIR) = 1)
begin
select substring(convert(varchar(1), nu_ipi), 1, 4) from dbo.t_STAGEAREACHAIR
end
But it returns more than 1 value though.
Have you an idea how I can do it?
Thanks|||First of all, there really is no need to put a subselect in the select you posted :
select substring(convert(varchar(SELECT len(nu_ipi) - 1 FROM dbo.t_STAGEAREACHAIR), nu_ipi), 1, 4) from dbo.t_STAGEAREACHAIR
I think you are looking for something like this
select substring(convert(Varchar(10), NU_IPS), 1, len(convert(Varchar(10), NU_IPS)) -1 from dbo.t_STAGEAREACHAIR
however I'm not exactly certain I've understood your problem fully...|||maybe i don't understand it fully either, but NU-IPS is already a varchar, so...
select left(NU_IPS,len(NU_IPS)-1) ...or alternatively
select replace(NU_IPS,'%','') ...|||r937 and Nephilim
I think You got it, that's what I wanted.
It works...
Really thanks!
Juliane
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment