Showing posts with label bunch. Show all posts
Showing posts with label bunch. Show all posts

Thursday, March 29, 2012

Converting data types

Having a slight problem. For whatever reason I had a column setup for nvchar but the only data i have in there is dates (MM/DD/YY) and a whole bunch of NULLs. I wanted to change the datatype to datetime but it gave me an error. I thought it was due to all the NULLs, so I removed all the nulls. It still doesn't work. I get the error : Conversion failed when converting datetime from character string.

I don't belive its because I have the data in mm/dd/yy format. I created another table and populated it with mm/dd/yy data as nvchar (50) and then converted to datetime and it worked fine.

any ideas?

Obviously, as you know, you get this error because the conversion could not convert some of the data (as it was not in the correct format). First of all, you can use IsDate function to see which data is giving you problem. Other than that, try this post. Just as a precaution, backup the table or database before you try anything.

http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1785290&SiteID=1

|||

Rather than trying to update the data type, try creating an additional field with a DateTime type. You can then copy all the dates that aren't null into this column and then drop the original column (and rename the new one if necessary).

|||

I would look through the data. When dates are stored as varchar, and especially if there isn't any validation when it is inserted into the database, you'll often see values like 01/01/3007 or 06/32/2007 or some other way it was entered that caused ambiguity with SQL Server. I've had the same thing happen in the past.

|||

Hi,

Review the Globalization configuration in the web.config, put en-US to work fine in the culture and uiculture attributes, by default is en-US, may be you change it.

greetings.

Tuesday, March 20, 2012

Convert VARCHAR to money value

Ok i know this is simple but i just don't know the syntax. What I have
is a bunch of values and i want to be able to display them as money
values with a $ in front.
eg.
16000000
1000
160000
TO THIS
$16,000,000.00
$1000.00
$16,000.000
I'm using MS SQL 2000
Cheers
I guess it's not straight forward by just using convert function to change
datatype to money.
You need to write a function which will append $ and will separate thousands
with comma.
Woodies_46@.hotmail.com wrote:
>Ok i know this is simple but i just don't know the syntax. What I have
>is a bunch of values and i want to be able to display them as money
>values with a $ in front.
>eg.
>16000000
>1000
>160000
>TO THIS
>$16,000,000.00
>$1000.00
>$16,000.000
>I'm using MS SQL 2000
>Cheers
Message posted via droptable.com
http://www.droptable.com/Uwe/Forums...ivity/200603/1

Monday, March 19, 2012

Convert VARCHAR to money value

Ok i know this is simple but i just don't know the syntax. What I have
is a bunch of values and i want to be able to display them as money
values with a $ in front.
eg.
16000000
1000
160000
TO THIS
$16,000,000.00
$1000.00
$16,000.000
I'm using MS SQL 2000
CheersI guess it's not straight forward by just using convert function to change
datatype to money.
You need to write a function which will append $ and will separate thousands
with comma.
Woodies_46@.hotmail.com wrote:
>Ok i know this is simple but i just don't know the syntax. What I have
>is a bunch of values and i want to be able to display them as money
>values with a $ in front.
>eg.
>16000000
>1000
>160000
>TO THIS
>$16,000,000.00
>$1000.00
>$16,000.000
>I'm using MS SQL 2000
>Cheers
Message posted via droptable.com
http://www.droptable.com/Uwe/Forum...tivity/200603/1|||On 7 Mar 2006 20:32:18 -0800, Woodies_46@.hotmail.com wrote:

> Ok i know this is simple but i just don't know the syntax. What I have
> is a bunch of values and i want to be able to display them as money
> values with a $ in front.
> eg.
> 16000000
> 1000
> 160000
> TO THIS
> $16,000,000.00
> $1000.00
> $16,000.000
>
> I'm using MS SQL 2000
> Cheers
Ideally, this formatting would be done in your front-end application (or
reporting tool), rather than being formatted by SQL.

Convert VARCHAR into Money Value

Ok i know this is simple but i just don't know the syntax. What I have
is a bunch of values and i want to be able to display them as money
values with a $ in front.

eg.

16000000
1000
160000

TO THIS

$16,000,000.00
$1000.00
$16,000.000

I'm using MS SQL 2000

Cheers(Woodies_46@.hotmail.com) writes:
> Ok i know this is simple but i just don't know the syntax. What I have
> is a bunch of values and i want to be able to display them as money
> values with a $ in front.
> 16000000
> 1000
> 160000
> TO THIS
> $16,000,000.00
> $1000.00
> $16,000.000
>
> I'm using MS SQL 2000

Normally, formatting should be done client-side. Not the least because
the format is dependent on regional settings. The above is not how I
want my decimal commas and thousands separator.

Nevertheless, you can do this:

declare @.x money
select @.x = 9009090909
select '$' + convert(varchar, @.x, 1)

--
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx

Sunday, March 11, 2012

convert table data into complex xml document

I would like to convert the following two tables into the XML document below
without a bunch of UNIONS. The reason being in my case i have hundereds of
tables w/ different fields all going into a single XML document. Is there
any way to use user defined functions or something to construct just one XML
document? Or is there a way i can convert all the foos into a string, all
the bars into a string etc. then concatinate them and return them as an xml
document?
TABLE FOO
x y
________________ ____________________
1 11
2 22
TABLE BAR
a b
________________ ____________________
3 33
4 44
Using Open XML how do you convert this into:
<rootfoobar>
<foos>
<foo x='1' y='11'/>
<foo x='2' y='22'/>
</foos>
<bars>
<bar a='3' b='33'/>
<bar a='4' b='44'/>
</bars>
</rootfoobar>
The UNIONS are not so bad (the mainteance of the query is rather ugly
though).
In SQL Server 2000, you either use the mapping schemas of the mid-tier
SQLXML component or FOR XML EXPLICIT queries.
If the data has no correlation, you can also use the XML templates in SQLXML
to put individual query results together.
In SQL Server 2005, you will be able to nest FOR XML and use the new PATH
mode that avoids the UNION all. See my blog entries and links to an MSDN
whitepaper on http://sqljunkies.com/weblog/mrys
HTH
Michael
"Daniel" <softwareengineer98037@.yahoo.com> wrote in message
news:%23l2gkbrbEHA.3716@.TK2MSFTNGP11.phx.gbl...
>I would like to convert the following two tables into the XML document
>below
> without a bunch of UNIONS. The reason being in my case i have hundereds of
> tables w/ different fields all going into a single XML document. Is there
> any way to use user defined functions or something to construct just one
> XML
> document? Or is there a way i can convert all the foos into a string, all
> the bars into a string etc. then concatinate them and return them as an
> xml
> document?
> TABLE FOO
> x y
> ________________ ____________________
> 1 11
> 2 22
>
>
> TABLE BAR
> a b
> ________________ ____________________
> 3 33
> 4 44
>
> Using Open XML how do you convert this into:
> <rootfoobar>
> <foos>
> <foo x='1' y='11'/>
> <foo x='2' y='22'/>
> </foos>
> <bars>
> <bar a='3' b='33'/>
> <bar a='4' b='44'/>
> </bars>
> </rootfoobar>
>
>

Wednesday, March 7, 2012

convert scientific notation to to decimal

I am importing a bunch of data which is all in varchar format which I cast into the relevant type on transfer to the production table. One of these columns contains decimals, but some of them are occasionally given in scientific notation (3.48E-02).
I am using

CAST (v1 AS decimal(18, 13))

to do the conversion, but that seems to be unable to handle the scientific notation. Does anyone know a way around this?Try converting to float first, like this:
CAST (CAST (v1 AS float(24)) AS decimal(18, 13))