zoukankan      html  css  js  c++  java
  • 9、变量的定义、赋值、使用,全局变量,if语句

    1、变量

    1)变量的定义:

    Declare  @sum  int

    2)变量的赋值:

    Set  @sun=1

    3)变量的使用:

    Print  @sum

    例:

    Declare  @sum  varchar20

    Set  @sun=abcdef

    Print  @sum

    2、全局变量(系统函数)

    (1)@@error

    返回上一次出现的错误的代号(是int型的)

    (2)@@rowcount

    返回受上次影响的行数

    例:

    求圆的面积?

    Declare  @pi  decimal(18,2), @r  decimal(18,2),@s  decimal(18,2)

    Set  @pi=3.14

    Set  @r=2

    Set  @s=@pi*@r*@r

    Print  @s 

     

    3、if语句

    判断一个数?

    Declare  @a int

    Set  @a=2

    If  @a>0

    Begin

      Print ‘这是一个大于0的数

    End

    Else if  @a=0

    Begin

      Print ‘这个数为0

    End

    Else 

    Begin

      Print ‘这是一个小于0的数

    End

    判断闰年?

    declare @y int

    set @y=2200

    if (@y%100=0 and @y%400=0) or(@y%100<>0 and @y%4=0)

    begin

      print '是闰年'

    end

    else

    begin

      print '不是闰年'

    end

  • 相关阅读:
    抓包来看ftp状态码
    socket基础篇
    密码复杂度检查函数
    time模块
    读取日志文件,搜索关键字,打印关键字前5行。yield、deque实例
    装饰器--函数
    yield用法
    字符编码
    pycharm + git实现两台电脑代码同步
    PyCharm常见用法
  • 原文地址:https://www.cnblogs.com/XMH1217423419/p/4133161.html
Copyright © 2011-2022 走看看