











CompTIA
Exam Vouchers
Save money on CompTIA exams
| Question of the day
Sign up to receive
interactive practice questions
for MCSE, CompTIA
Cisco and other exams
| TestKing
Get MCSE, MCSD, CCNA, CCNP,A+, N+ and many more | * ExamSheets *
Guide for Success!
Actual Questions & Answers
MCSE, MCSD, A+ ,CCNA, CCNP
Oracle 8i, Oracle 9i Online practice tests
Certification sites Online university Online college Online education Distance learning Software forum Server administration forum Programming resources
|
|  |
cocolocopolo
Senior Member
Registered: Apr 2001 Location: Los Angeles Country: USA State: Certifications: A+, Network+, CCNA Working on: MCDBA
Total Posts: 287
|
|
Error Handling
From "Microsoft SQL Server 2000 Database Design & Implementaton Training Kit", there is a training question to create a database
(by the name of BookShopDB) and several tables, one of the table is Customers (but I created tblCustomers at that time).
Now, when it comes to Chapter 8 "Implementing Stored Procedures"
to practise Error Handling, I followed the instruction, entered the following code:
Declare @r_Code int
Execute @r_Code=dbo.AddCustomer
@FirstName= 'Jamie', @LastName= 'Marra',
@Phone = '425-555-1212', @Address1 = '20 Oak St., SE',
@City = 'Remy', @State = 'WA', @Zip = '98888'
If @r_Code = 4
Begin
Print 'A database error has occured.
Please contact teh help desk for assistance.'
End
If @r_Code = 1
Print 'You must specify a value for the firstname or lastname.'
Else If @r_Code = 2
Print 'You must specify a value of the phone number.'
Else If @r_Code = 3
Print 'You must provide all address information, Street address, City, State and Zipcode.'
Else If @r_Code = @@Identity
Select [Customer ID] = 'The new customer is: ' +
Convert(Char(2), @r_Code)
But I got error:
Server: Msg 208, Level 16, State 1, Procedure AddCustomer, Line 16
Invalid object name 'BookShopDB.dbo.Customers'.
I understand there is no such table by the name of Customers (only tblCustomers).
So I modified the codes and enter following code instead:
Select [BookShopDB].[dbo].[tblCustomers].[Customer ID]= 'The new Customer ...'
But got another error again that:
Line 23: Incorrect syntax near '='.
Besides drop the tblCustomers, then re-create Customers table, I wonder if there is another way to fix this error???
Please help.
__________________
cocolocopolo
Report this post to a moderator
|
|
07-01-02 05:54 AM
|
|
2lazybutsmart
The Game Never Ends

Registered: Jun 2002 Location: Toronto Country: Canada State: Certifications: MCSD, MCP Working on: MCSD.net, MCDBA, MCT
Total Posts: 684
|
|
looks like the error is comming from the dbo.AddCustomer stored proc. can u print that out for us here on the thread so we can analyze it a bit.
i hope ur not facing role problem, i hate them.
__________________
Crime is Common, Logic is Rare.
TechExams.net moderator
Report this post to a moderator
|
|
07-01-02 05:58 AM
|
|
kingsunl
Junior Member M
Registered: Nov 2001 Location: Richmond Country: Canada State: Certifications: MCSD Working on: MCSD .NET
Total Posts: 8
|
|
Specifying Aliases
quote:
Select [BookShopDB].[dbo].[tblCustomers].[Customer ID]= 'The new Customer ...'
When specifying aliases, the correct syntax is:
Select 'The new Customer'=[BookShopDB].[dbo].[tblCustomers].[Customer ID],...
Place the alias first followed by an equality operator and then the column name.
Personally, I like to do it this way:
Select [BookShopDB].[dbo].[tblCustomers].[Customer ID] AS 'The new Customer', ...
The third way is:
Select [BookShopDB].[dbo].[tblCustomers].[Customer ID] 'The new Customer', ...
The word 'AS' is removed.
Report this post to a moderator
|
|
07-02-02 04:18 PM
|
|
cocolocopolo
Senior Member
Registered: Apr 2001 Location: Los Angeles Country: USA State: Certifications: A+, Network+, CCNA Working on: MCDBA
Total Posts: 287
|
|
Dear kingsunl, thanks for your advice.
The MCSE Training Kit likes us to come up a result in this way:
"The new customer is 11 (or 12 so on so on)'
So I follow your suggesttion and changed the last "Select" clause like this way:
Select [BookShopDB].[dbo].[tblCustomers].[Customer ID] AS 'The new Customer'
but after this clause, how can I combine the @r_Code so the result can come up a customer ID number???
Thanks in advance.
__________________
cocolocopolo
Report this post to a moderator
|
|
07-03-02 05:12 AM
|
|
kingsunl
Junior Member M
Registered: Nov 2001 Location: Richmond Country: Canada State: Certifications: MCSD Working on: MCSD .NET
Total Posts: 8
|
|
quote:
But I got error:
Server: Msg 208, Level 16, State 1, Procedure AddCustomer, Line 16
Invalid object name 'BookShopDB.dbo.Customers'.
You must look at line 16 of AddCustomer procedure. There is no point modifying the current codes that call this procedure.
quote:
Else If @r_Code = @@Identity
Select [Customer ID] = 'The new customer is: ' +
Convert(Char(2), @r_Code)
will work if AddCustomer procedure is straightened out.
Report this post to a moderator
|
|
07-03-02 02:58 PM
|
|
|
MCSE exam notes
Forum Rules: Who Can Read The Forum? Any registered user or guest.
Who Can Post New Topics? Any registered user.
Who Can Post Replies? Any registered user.
Changes: Messages can be edited by their author.
Posts: HTML code is OFF. Smilies are ON. vB code is ON. [IMG] code is ON. |
|
ExamNotes forum archive
|