Beida Jade Bird Phase III SQL programming using variables and If-else

Source: Internet
Author: User

1 --declaring Variables2 Declare @age int3 Declare @name varchar( -)4 5 6 --Assignment (constant value)7 Set @age= -8 Select @name='Zhang San'9 Ten  One --isolated from database and assigned value A Set @name=(SelectStudentname fromStudentwhereStudentno=10000) - Print @name - Select @name=Studentname fromStudentwhereStudentno=10000 the Print @name - Go -  -  + --find the students who force Mogaoyizhang the adjacent school number -  +  A --1. Find Force Mogaoyizhang's School number at Declare @StuNo int - Select @StuNo=Studentno fromStudentwhereStudentname='Force Mogaoyizhang' - Print @StuNo - --2. Students who force Mogaoyizhang the adjacent school number - Select *  fromStudentwhereStudentno=@StuNo+1 orStudentno=@StuNo-1 - Go in  -  to --set and select differences + Declare @address varchar( -) - --when a query statement returns multiple values, set error, select retains last value the Select @address=Address fromStudent * Print @address $ GoPanax Notoginseng  -  the  +  A Print 'name of the local server:'+@ @servername the Print 'version of SQL:'+@ @version +  -  $ Select @ @servername  as 'name of the local server' $ Select @ @version  as 'version of SQL' - Go -  the  - Declare @StuNo int,@name varchar( -),@date datetime,@SubNo int,@score intWuyi Set @StuNo=10000   --Study number Assignment the Set @date='2013-2-17'   --Date value Assignment - --Check the name according to the school number Wu Select @name=Studentname fromStudentwhereStudentno=@StuNo - --Check account number according to account name About Select @SubNo=Subjectno fromSubjectwhereSubjectname='Java Logic' $ --search for results based on criteria - Select @score=Studentresult fromResultwhereStudentno=@StuNo  andSubjectno=@SubNo  andExamdate=@date - Print 'the name is:'+@name - Print 'The results are:'+Convert(varchar( -),@score) A Print 'The results are:'+cast(@score  as varchar( -)) + Go the  -  $ --the Java exam score for the student number 20012 the Declare @stuno int,@subno int,@score int the Set @stuno=20012 the Select @subno=Subjectno fromSubjectwhereSubjectname='Java Logic' the  -  in Select @score=Studentresult fromResultwhereStudentno=@stuno  andSubjectno=@subno the Print 'The 20012java results are:'+Convert(varchar( -),@score) the Go About  the  the --If-else the --Query the account number for Java logic + Declare @subno int,@date datetime,@avg decimal(5,2) - Set @date='2013-2-17' --Time the Select @subno=Subjectno fromSubjectwhereSubjectname='Java Logic'Bayi Print @subno the --check the average score for 2013-2-17java exams the Select @avg=avg(Studentresult) fromResultwhereExamdate=@date  andSubjectno=@subno -  -  the if(@avg>= -) the begin the Print 'Excellent results' the End - Else the begin the Print 'Poor grades' the End

Beida Jade Bird Phase III SQL programming using variables and If-else

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.