CREATE VIEW 三建_SPJ (SNO,PNO,QTY)
AS SELECT SNO,PNO,QTY
FROM SPJ
WHERE JNO=(SELECT JNO
FROM J
WHERE JNAME='三建');
第一行显示错误“语法错误,CREATE VIEW必须是批处理中仅有的语句”,请问该怎样创建视图? ------最佳解决方案-------------------- CREATE VIEW 三建_SPJ (SNO,PNO,QTY)
AS SELECT SNO,PNO,QTY
FROM SPJ
WHERE JNO in (SELECT JNO
FROM J
WHERE JNAME='三建');
把=改为 in ,双击错误看看是否有其它字符 ------其他解决方案-------------------- 或者试试:
GO
CREATE VIEW 三建_SPJ (SNO,PNO,QTY)
AS SELECT SNO,PNO,QTY
FROM SPJ
WHERE JNO In (SELECT JNO --这里改成IN比较安全,如果保证只有一条,那么用等号也可以
FROM J
WHERE JNAME='三建'); ------其他解决方案-------------------- CREATE VIEW 三建_SPJ
AS SELECT SNO,PNO,QTY
FROM SPJ
WHERE JNO=(SELECT JNO
FROM J
WHERE JNAME='三建'); ------其他解决方案-------------------- 视图名不需要指定列名
CREATE VIEW 三建_SPJ
AS
SELECT SNO ,
PNO ,
QTY
FROM SPJ
WHERE JNO = ( SELECT JNO
FROM J
WHERE JNAME = '三建'
) ;