Home > Archive > SQL server exams > May 2002 > What CONVERT???





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author What CONVERT???
cocolocopolo

2002-05-13, 3:55 am

Sorry, another syntax error again.

I made correction on yesterday's syntax error, then keep going create another tables as following:


Create Table BookShopDB.dbo.tblCustomers
(CustomerID SmallInt Identity(10,1) not null,
FirstName varchar(30) not null Default 'unknown',
LastName varchar(30) not null Default 'unknown',
Phone varchar(24) not null Default 'unknown',
Address1 varchar(60) not null Default 'unknown',
Address2 varchar(60) not null Default 'unknown',
City Varchar(15) not null Default 'unknown',
State varchar(7) not null Default 'unknown',
Zip varchar(12) not null Default 'unknown')

Create Table BookShopDB.dbo.tblOrders
(OrderID SmallInt Identity not null,
CustomerID SmallInt not null,
EmployeeID SmallInt not null,
Amount money not null Default '0',
OrderDate DateTime not null,
DeliveryDate DateTime null,
PaymentID TinyInt not null,
StatusID TinyInt not null)

Create Table BookShopDB.dbo.tblOrderStatus
(StatusID TinyInt not null,
StatusDescrip varchar(25) not null)

Create Table BookShopDB.dbo.FormOfPayment
(PaymentID TinyInt not null,
PaymentDescrip varchar(12) not null)

But got error:

Server: Msg 257, Level 16, State 3, Line 12
Implicit conversion from data type varchar to money is not allowed.
Use the CONVERT function to run this query.
Server: Msg 1750, Level 16, State 1, Line 12
Could not create constraint. See previous errors.



???? Use the CONVERT function to run this query. But how to use CONVERT???
hard_coder

2002-05-13, 10:22 am

--> Amount money not null Default '0',
should read:
Amount money not null Default 0.0,

The single quotes are telling SQL Server you want the literal string "0" to be the default (in a money type) which it is not able to implicitly convert from a string. Putting 0 (zero) without the quotes will also work.

To use Convert, you would put:
CONVERT(MONEY, '0') but should be reserved only when retrieving data and doing conversions on the fly.
Example:
PRINT 'The amount you owe is $' +
CONVERT(VARCHAR(10), AMOUNT)

This will convert the AMOUNT column value to a string so it can be concatenated to the preceding string.

Do not use CONVERT or CAST in the creation of columns for a table.
cocolocopolo

2002-05-14, 3:07 am

Thanks hard_coder.
Sponsored Links





Free Braindumps | MCSE braindumps software forum

Copyright 2003 - 2008 examnotes.net