閱讀992 返回首頁    go 阿裏雲 go 技術社區[雲棲]


SQL基礎2

--輸出字符串"I love you "對應的ASCII值和字符
declare @pos smallint, --位置
        @string varchar(10) --字符串
set @pos = 1;
set @string = 'I love you'

--datalength是一個全局數據,返回數據的長度
while (@pos <= datalength(@string))
begin 
    select ascii(substring(@string, @pos, 1)) as AsciiCode,   --獲取ASCII碼
           char(ascii(substring(@string, @pos, 1))) as ascchar--獲取對應的字符
    set @pos = @pos + 1
end

create database studentInfo
on primary
( name = stu_data,
  filename = 'd:\stu_data.mdf',
  size = 3,
  maxsize = 15,
  filegrowth = 1)
log on
(
  name = stu_log,
  filename = 'd:\stu_log.ldf',
  size = 1,
  maxsize = 12,
  filegrowth = 10%
)

use student
go
create proc tea_pro
(@no char(6), @name nvarchar(8), @sex nchar(1), @age int, @title nchar(5), @tel varchar(12)
, @salary decimal(7), @num char(10))
as
 insert into teacher_info values(@no, @name, @sex, @age, @title, @tel, @salary, @num)
go

use student
go
create proc stud_proc
    (@startdate datetime, @enddate datetime, @recordcount int output) --用output指定為返回值
as
    if (@startdate is null or @enddate is null)
    begin
        raiserror('Null value are invalid!', 5, 5)
        return
    end
    select * from stud_info
    where birthday between @startdate and @enddate
    select @recordcount = @@rowcount
go


 

最後更新:2017-04-02 00:06:51

  上一篇:go 《江南Style》騎著社交網絡之馬
  下一篇:go 《人生的智慧》第一章 基本的劃分