Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Friday, March 23, 2012

Row values to string

Hi,
How can I create a string containing all values from a row in a
table(SELECT).
sample:
ID | NAME
--
1 | John -> "1,John"
2 | Alexander -> "2,Alexander"
Thank you,
Roby Eisenbraun MartinsConvert all the column values to a character compatible type and use the
concatenation operator like:
SELECT CAST( id AS VARCHAR ) + ',' +
CAST( name AS VARCHAR ( 30 ) ) + ',' +
..
FROM tbl ;
Anith|||What do you want to do with the string? You can use DTS to export a table or
view to a comma delimited text file.
"Roby Eisenbraun Martins" <RobyEisenbraunMartins@.discussions.microsoft.com>
wrote in message news:BDF4B30A-70E8-4D3C-8D35-7C095D2C167F@.microsoft.com...
> Hi,
> How can I create a string containing all values from a row in a
> table(SELECT).
> sample:
> ID | NAME
> --
> 1 | John -> "1,John"
> 2 | Alexander -> "2,Alexander"
> Thank you,
> Roby Eisenbraun Martins
>sql

Wednesday, March 7, 2012

Rounding very small negative numbers to string

Hi,
I'm trying to round a very small negative number, e.g. -.024, to a string.
If I round -.024 to 1 place, I get 0.0
However, when converting to string, I get .-0
Is there some combination of functions to get rid of the minus sign in such
a situation, or do I have to put in an IF condition to check if number < .05
and change it to ABS?
Below is code that is resulting in -0.
Thanks.
Alan
DECLARE @.Value float(53)
DECLARE @.ValueRounded float(53)
SET @.Value = -.024 -- Any negative number < .05
SELECT @.Value
SET @.ValueRounded = ROUND(@.Value, 1)
SELECT @.ValueRounded
SELECT CONVERT(CHAR(6), @.ValueRounded)What about this?
DECLARE @.Value float(53)
DECLARE @.ValueRounded decimal(6,1)--convert to decimal
SET @.Value = -.024 -- Any negative number < .05
SELECT @.Value
SET @.ValueRounded = ROUND(@.Value, 1)
SELECT @.ValueRounded
SELECT CONVERT(CHAR(6), @.ValueRounded)
Denis the SQL Menace
http://sqlservercode.blogspot.com/
Alan Z. Scharf wrote:
> Hi,
> I'm trying to round a very small negative number, e.g. -.024, to a string.
> If I round -.024 to 1 place, I get 0.0
> However, when converting to string, I get .-0
> Is there some combination of functions to get rid of the minus sign in suc
h
> a situation, or do I have to put in an IF condition to check if number < .
05
> and change it to ABS?
> Below is code that is resulting in -0.
> Thanks.
> Alan
>
> DECLARE @.Value float(53)
> DECLARE @.ValueRounded float(53)
> SET @.Value = -.024 -- Any negative number < .05
> SELECT @.Value
> SET @.ValueRounded = ROUND(@.Value, 1)
> SELECT @.ValueRounded
> SELECT CONVERT(CHAR(6), @.ValueRounded)|||Menace,
Thanks very much. I figured there must be a way.
Alan
"SQL Menace" <denis.gobo@.gmail.com> wrote in message
news:1149092714.650915.239590@.j55g2000cwa.googlegroups.com...
> What about this?
>
> DECLARE @.Value float(53)
> DECLARE @.ValueRounded decimal(6,1)--convert to decimal
> SET @.Value = -.024 -- Any negative number < .05
> SELECT @.Value
> SET @.ValueRounded = ROUND(@.Value, 1)
> SELECT @.ValueRounded
> SELECT CONVERT(CHAR(6), @.ValueRounded)
>
> Denis the SQL Menace
> http://sqlservercode.blogspot.com/
> Alan Z. Scharf wrote:
string.
such
.05
>|||Is this what u need?
DECLARE @.Value float(53)
SET @.Value = -.025
SELECT ABS(Floor(@.Value))
Regards
Sudarshan Selvaraja
"Alan Z. Scharf" wrote:

> Hi,
> I'm trying to round a very small negative number, e.g. -.024, to a string.
> If I round -.024 to 1 place, I get 0.0
> However, when converting to string, I get .-0
> Is there some combination of functions to get rid of the minus sign in suc
h
> a situation, or do I have to put in an IF condition to check if number < .
05
> and change it to ABS?
> Below is code that is resulting in -0.
> Thanks.
> Alan
>
> DECLARE @.Value float(53)
> DECLARE @.ValueRounded float(53)
> SET @.Value = -.024 -- Any negative number < .05
> SELECT @.Value
> SET @.ValueRounded = ROUND(@.Value, 1)
> SELECT @.ValueRounded
> SELECT CONVERT(CHAR(6), @.ValueRounded)
>
>
>|||BTW, FLOAT is an approximate representation. You would probably be better
off representing your data as a NUMERIC type.
"Alan Z. Scharf" <ascharf@.grapevines.com> wrote in message
news:Od%23oc2MhGHA.3756@.TK2MSFTNGP02.phx.gbl...
> Hi,
> I'm trying to round a very small negative number, e.g. -.024, to a string.
> If I round -.024 to 1 place, I get 0.0
> However, when converting to string, I get .-0
> Is there some combination of functions to get rid of the minus sign in
> such
> a situation, or do I have to put in an IF condition to check if number <
> .05
> and change it to ABS?
> Below is code that is resulting in -0.
> Thanks.
> Alan
>
> DECLARE @.Value float(53)
> DECLARE @.ValueRounded float(53)
> SET @.Value = -.024 -- Any negative number < .05
> SELECT @.Value
> SET @.ValueRounded = ROUND(@.Value, 1)
> SELECT @.ValueRounded
> SELECT CONVERT(CHAR(6), @.ValueRounded)
>
>
>|||>> I'm trying to round a very small negative number, e.g. -.024, to a string
. <<
Why are you formatting data in the back end? The basic principle of a
tiered architecture is that display is done in the front end and never
in the back end. This a more basic programming principle than just SQL
and RDBMS.