if exists(select * from sysobjects where name=@provinceName)
set @f=1
else
set @f=0
set @f=1
else
set @f=0
解决方案 »
- 用SQL语句怎么才能得到基本个月的日期从1号到31号
- 查询3张表中的数据问题
- 有什么方法把两个结构相同的表的不同的记录找出来?
- 多表查询 请教高手!!!!!!!!!!在线
- 全志A13怎么刷机
- 调用一个存储过程返回记录集的问题???
- 为什么SQL SERVER 2000不能在WINXP下运行,有没有办法解决?
- 已知sqlserver2000的一张表存在主键,怎么遍历与其建立外键关系的表
- 如何连接指定ip地址的SQL Server数据库?
- sky_blue(老衲)兄的100分, 谢谢!(详情见一个初中级难度问题请高手帮忙! 分好说, 帮我解决的至少500。帖子)
- ntext 内容替换问题</p> 替换成 </p><p></p>以前的方法会死循环
- sql2000和SQL2005可以同时安装吗?
set @f=1
else set @f=0
这样就行了,变量在字符串内要使用也必须在字符串里面声名.
exec(@s1) 明显的语法错误
set @f=1
else set @f=0
on MyTable
for update
as
set nocount on
if update(bustype_name)
declare @provinceName varchar(100);
declare @s1 varchar(250)
declare @f varchar(10)
declare provinceCursor cursor for select province from address where isnull(address_name,'')=''
open provinceCursor
fetch next from provinceCursor into @provinceName
while(@@fetch_status=0)
begin
set @provinceName = 'dx_business_'+@provinceName
print(@provinceName)
--set @s1 = 'if exists(select * from sysobjects where name='''+@provinceName+''') set @f=1 else set @f=0'
--*************************************************************************
if exists(select * from sysobjects where name='+@provinceName+')
set @f=1
else
set @f=0
--****************************************************************************
print (@f)
if (@f=1)
print('exists') else
print (@f)
set @provinceName = '';
fetch next from provinceCursor into @provinceName end
close provinceCursor
deallocate provinceCursor
begin
set @f=1
end
else
set @f=0
end
on MyTable
for update
as
set nocount on
if update(bustype_name)
declare @provinceName varchar(100);
declare @s1 varchar(250)
declare @f varchar(10)
declare provinceCursor cursor for select province from address where isnull(address_name,'')=''
open provinceCursor
fetch next from provinceCursor into @provinceName
while(@@fetch_status=0)
begin
set @provinceName = 'dx_business_'+@provinceName
print(@provinceName)
--set @s1 = 'if exists(select * from sysobjects where name='''+@provinceName+''') set @f=1 else set @f=0'
--*************************************************************************
if exists(select * from sysobjects where name=@provinceName)
begin
set @f=1
end
else
begin
set @f=0
end
--****************************************************************************
print (@f)
if (@f=1)
print('exists') else
print (@f)
set @provinceName = '';
fetch next from provinceCursor into @provinceName end
close provinceCursor
deallocate provinceCursor
我6楼的
掉了个begin
if exists(select * from sysobjects where name=@provinceName)
begin
set @f=1
end
else
begin
set @f=0
end
一直觉得如果要执行带有变量的语句就要用exec。···看来进入了误区。
只是不知道我这里的问题和文章中的问题有什么区别?
·······················在触发器中的变量老提示要声明变量的问题 急疯了??
完整代码是
CREATE TRIGGER tougao ON dbo.yichangxinwen
instead of insert
asdeclare @biaoming nvarchar(200)
if (select quanxian from denglu where yonghu = (select yonghu from inserted)) = '编辑'
begin
set @biaoming = 'adlishi'
endif (select quanxian from denglu where yonghu = (select yonghu from inserted)) = '通讯员'
begin
set @biaoming = 'txlishi'
endif (select quanxian from denglu where yonghu = (select yonghu from inserted)) = '本台记者'
begin
set @biaoming = 'bjlishi'
endif (select quanxian from denglu where yonghu = (select yonghu from inserted)) = '集体记者'
begin
set @biaoming = 'jjlishi'
end
if exists(select * from yichangxinwen where yonghu = (select yonghu from inserted) and nianyue = (select convert(char(7),getdate(),20)) )
begin insert yichangxinwen(biaoti,wenzhang,select1,yonghu,select2,yonghu2,shijian,nianyue,shenghe,danwei,riqi,canshu)
select biaoti,wenzhang,select1,yonghu,select2,yonghu2,shijian,nianyue,shenghe,danwei,riqi,canshu from inserted;
update txlishi
set touzong=touzong+1
from @biaoming inner join inserted yichangxinwen on @biaoming.yonghu = yichangxinwen.yonghu and @biaoming.nianyue = (select convert(char(7),getdate(),20))
endif not exists(select * from yichangxinwen where yonghu = (select yonghu from inserted) and nianyue = (select convert(char(7),getdate(),20)) )
begin
insert yichangxinwen(biaoti,wenzhang,select1,yonghu,select2,yonghu2,shijian,nianyue,shenghe,danwei,riqi,canshu)
select biaoti,wenzhang,select1,yonghu,select2,yonghu2,shijian,nianyue,shenghe,danwei,riqi,canshu from inserted;
insert @biaoming(yonghu,nianyue,touzong)
select yonghu,convert(char(7),getdate(),20),1 from inserted
end结果是老说@biaoming 必须声明 是不是触发器中变量的使用方法不正确????
在线等!!!!
insert @biaoming(yonghu,nianyue,touzong) --你把@biaoming当表用了