zoukankan      html  css  js  c++  java
  • 关于sqlserver的储存过程的杂记20091218

    declare @sql nvarchar(2000)

    set @sql='select * into #temp1 from product'

    exec(@sql)

    select * from #temp1

    这样在查询分析器中执行会报如下错误

     

    (3274 行受影响)

    消息208,级别16,状态0,第4

    对象名'#temp1' 无效。

     

    可以改用

    declare @sql nvarchar(2000)

    set @sql='select * into #temp1 from product select * from #temp1'

    exec(@sql)

     

    游标的效率不高,一般需要使用其这方式替代

     

    下面这段代码是正确的

    declare @productcode nvarchar(200)

    set @productcode='00000001'

    declare @productName nvarchar(2000)

     

    select @productName=[ProductName] from product where productcode=@productcode

    print @productName

    --select @productName=productName from product where productcode=@productCode

    if exists(select [ProductName] from product where productcode=@productCode)

        print @productName

    else

        print '==='

    但是如果改成这样就不行了

    declare @productcode nvarchar(200)

    set @productcode='00000001'

    declare @productName nvarchar(2000)

     

    select @productName=[ProductName] from product where productcode=@productcode

    print @productName

     

    if exists(select @productName=productName from product where productcode=@productCode)

        print @productName

    else

        print '==='

     

    想说明的是在exists含数中是不能使用@productName=productName的方式来赋值的

  • 相关阅读:
    正则表达式语法
    Linux之Shell脚本计算命令行的所有和
    Linux之匹配符
    Linux之ls命令
    Linux之Shell的算术运算
    Linux 之 shell 比较运算符
    tensorboard的使用
    模型训练减少随机性
    keras 下载预训练模型报错SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)
    Deep face recognition: a survey v4
  • 原文地址:https://www.cnblogs.com/lexus/p/1627242.html
Copyright © 2011-2022 走看看