The basis of their database to see the problem

2010-11-11  来源:本站原创  分类:Database  人气:73 

Test: to the output parameter assignment, output will not be without error?

Select to print the test results with: 20 null
Conclusion: No error will output NULL

Printed with the Print Results: No output Conclusion: do not output error is not more amazing is NULL: not even the value of the output is not empty

- Create a stored procedure
use MySchool
GO
if exists (select * from sysobjects where name = 'proc_stuInfo')
drop proc proc_stuInfo
GO
create proc proc_stuInfo
@ Age int,
@ Sum int output,
@ X int
as
- Note that this statement is true.
select @ sum = 100 - 1

if (@ sum <20)
begin
raiserror ('age of error, must be an integer greater than 20', 16,1)
return
end
print 'age' + convert (varchar (5), @ age) + 'the following is:'
select * from stuInfo where stuAge <@ age
select @ sum = count (*) from stuInfo where stuAge <@ age
GO
- Part one: using select Print
- Call a stored procedure
declare @ sum int
declare @ x int
set @ x = 20
- Note: This place can be specified assignment, not in the stored procedure in accordance with the parameters defined in the order of assignment.
exec proc_stuInfo 25, @ sum, @ x - 2

select @ x, @ sum - 3
GO

- Second: Use Print Print
- Call a stored procedure
declare @ sum int
declare @ x int
set @ x = 20
- Note: This place can be specified assignment, not in the stored procedure in accordance with the parameters defined in the order of assignment.
exec proc_stuInfo 25, @ sum, @ x - 2

print convert (varchar (10), @ x) + convert (varchar (10), @ sum) - 3
GO
-------------------------------------------------- --------------------------------
Testing: The following T-SQL statement to run the results?
Test results: failed Conclusion: T-SQL in the if ... else .. can not begin .. end ..

Example:
declare @ a int
set @ a = 48
if @ a> 50
print 'pass'
else
if @ a <= 0
print 'did not take the exam'
else
print 'failed'
-------------------------------------------------- --------------------------------
This stored procedure can be performed correctly though, but do not use the aggregate functions plus grop by

if exists (select * from sysobjects where name = 'price_proc')
drop proc price_proc
GO
create proc price_proc (@ count int output, @ avg_price money
output, @ type char (12) = 'business') as
select @ count = count (*),avg_price = avg (price) from titles where type = @ type
-------------------------------------------------- --------------------------------
Testing: Perform the following the results of this stored procedure What is it?
Test results: will print out: Please enter a written exam pass line test results: NULL can be assigned to the variable, and can be judged by null

create proc stu_exam
@ W int = null
as
if @ w is null
begin
print 'Please enter a written exam pass line'
return
end
GO

exec stu_exam
-------------------------------------------------- ------------------------

相关文章