T-SQL Programming basics

Source: Internet
Author: User
Tags rand

Getting started with T-SQL programming Mini-Games

The basics of T-SQL programming include declaring variables, if judgments, while loops, and using some basic functions.

Remember when in school, wrote a two people to fight the text output game.

On the Code

Alter procUsp_paly asDeclare @paly1 nvarchar( -),@paly2 nvarchar( -)Declare @atk1 int,@atk2 intDeclare @hp1 int,@hp2 intSet @paly1 ='Mystic Arab'Set @paly2 ='Lu BU'Set @hp1 =  +;Set @hp2 =  +;Declare @rand int,@times int;Set @times = 0;Set @rand = 0;  while @hp1 > 0  and @hp2> 0   begin     Set @times = @times+1; Print 'Section'+ cast(@times  as varchar(Ten))+'rounds'      Set @rand = RAND()* -;--100 in random numbers, every turn is better than seeing who shoots first.      --Both sides attack, each time randomly      Set @atk1 = cast(RAND()*  -  as int)+Ten;--attack 10 to      Set @atk2 = cast(RAND()*  +  as int)+ +;--attack 40 to      if @rand> -        begin          --turn-based, one-man round, player 1 attacking player 2          Set @hp2 = @hp2 -@atk1; Print @paly1 +'Attack'+@paly2+' , '+@paly2+'Damage'+cast(@atk1  as varchar(Ten))          --Judging if @paly2 's dead.          if @hp2<=0           begin              Print @paly1 +'Victory!'               Break; End                        --Player 2 attacking player 2 not dead          Set @hp1 = @hp1 -@atk2; Print @paly2 +'Attack'+@paly1+' , '+@paly1+'Damage'+cast(@atk2  as varchar(Ten))          --Judging if @paly2 's dead.          if @hp1<=0           begin              Print @paly2 +'Victory!'               Break; End            End       Else        begin                      --Player 2 attacking player 1 not dead              Set @hp1 = @hp1 -@atk2; Print @paly2 +'Attack'+@paly1+' , '+@paly1+'Damage'+cast(@atk2  as varchar(Ten))              --Judging if @paly2 's dead.              if @hp1<=0               begin                  Print @paly2 +'Victory!'                   Break; End                                 --turn-based, one-man round, player 1 attacking player 2              Set @hp2 = @hp2 -@atk1; Print @paly1 +'Attack'+@paly2+' , '+@paly2+'Damage'+cast(@atk1  as varchar(Ten))              --Judging if @paly2 's dead.              if @hp2<=0               begin                  Print @paly1 +'Victory!'                   Break; End             End         Print '-----------------------------------------'   End Go  

Operating effects at a glance

nice!

T-SQL Programming basics

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.