• sql基础知识


    code:

    /********************************************/
    /*      CREATE PROC HYEY.WL 09-06-23        */
    /********************************************/
    --T-sql 查询
    SELECT * FROM dbo.TabTest
    
    --删除表中内容
    --TRUNCATE TABLE  dbo.TabTest
    
    -- 要创建存储过程的数据库
    
    USE Northwind
    
    -- 判断要创建的存储过程名是否存在
    IF(Select name From sysobjects Where name ='MyTestProc' And Type='p')
    
    -- 删除存储过程
    
    Drop Procedure dbo.MyTestProc
    GO
    
    -- 创建存储过程
    CREATE PROC dbo.MyTestProc
    
    -- 存储过程参数
    @sumPrice money 
    AS
    
    set @sumPrice = 1.1
     -- 存储过程语句体
    SELECT @sumPrice=SUM(testNum) from dbo.TabTest
    
    SELECT testID , cast(cast(str(SUM(testNum)/@sumPrice*100,5,2)   as   varchar)as   varchar)+'%'   AS Per INTO #TempPer FROM dbo.TabTest GROUP BY testID
    
    SELECT * FROM #TempPer
    
     -- 执行
     GO
    
    
    -- 执行存储过程
    
    EXEC MyTestProc
    
    GO
    
    --EXEC csp_AddInfo 'Junn.A','123456',20,'男'
    DECLARE @sumPrice MONEY
    EXEC MyTestProc @sumPrice
    
    
    --Test PROC
    DECLARE @sumPrice MONEY
    
    SELECT @sumPrice=SUM(testNum) from dbo.TabTest
    
    SELECT testID ,SUM(testNum)/@sumPrice AS Per INTO #TempPer FROM dbo.TabTest GROUP BY testID
    
    
    SELECT * FROM #TempPer
    
    --Test WL one
    declare   @data   as   decimal(18,5)   
    set   @data   =   0.12345   
        
    select   cast(cast(@data   *   100   as   decimal(18,2))   as   varchar(10))   +   '%'   as   结果
    
    
    --Test WL two
    
    declare   @a   decimal(15,4)   
    set   @a=.1234   
    select   cast(cast(@a*100   as   varchar)as   varchar)+'%'   
    select   cast(cast(str(@a*100,5,2)   as   varchar)as   varchar)+'%' 
    
    
    
    

           快速评论通道--您对本文的宝贵意见:
           
    感谢您的鼓励和批评,它将是我进步的动力

  • 相关阅读:
    HDU 1010 Tempter of the Bone
    HDU 4421 Bit Magic(奇葩式解法)
    HDU 2614 Beat 深搜DFS
    HDU 1495 非常可乐 BFS 搜索
    Road to Cinema
    Sea Battle
    Interview with Oleg
    Spotlights
    Substring
    Dominating Patterns
  • 原文地址:https://www.cnblogs.com/Leo_wl/p/1764741.html
Copyright © 2020-2023  润新知