如 表A和表B 将A表插入B表 其中A表有三个字段 id sex isStudent ;B表中也有id sex isStudent这三个字段但现在A表中来的数据有问题 sex里有些不是‘男’,‘女’ 还有其他非法的 isStudent 有些不是‘是’,‘否’ 也有些非法的 就是这两个字段需要在插入的时候过滤 如果sex 是‘男’,‘女’而不是其他非法的就插入 如果不是‘男’,‘女’而是其他非法数据就跳过不插入 求写一段存储过程啊 帮忙啊
------解决方案--------------------
insert into tableB
select * from tableA where (sex='男'or sex='女' )and (isStudent='是' or isStudent ='否')
------解决方案--------------------
insert into B(id ,sex, isStudent )
select id, sex, isStudent
from A
where sex in(N'男',N'女') and isStudent in(N'是',N'否')
------解决方案--------------------
IF EXISTS(SELECT * FROM sys.procedures WHERE object_id = OBJECT_ID('test'))
DROP PROC test
GO
CREATE PROCEDURE test
AS
BEGIN
insert into tableB
select *
from tableA
where (sex='男'or sex='女' )
and (isStudent='是' or isStudent ='否')
END
/*
exec test
*/
加个存储过程外套就好