导航
  • 主页
  • 基础类
  • 应用实例
  • 新技术前沿

帮忙关于sql语句

suisuibianbian 2004-01-29 09:30:01
INSERT INTO WHNEC.TBLCS_SalesDepartment(FDSALESCODE, FDSALESNAME, FDPROVINCE, FDREGION, FDADDRESS, FDPOST, FDCONTACT, FDTELEPHONE, FDMOBILE, FDFAX, FDEMAIL, FDDEGREE, FDREMARK) VALUES ('0002','11',(SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '北京' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0001'),(SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '华东' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0002'),'','','','','','','',(SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '受理中心' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0003'),'')
显示说缺少表达式,怎么改?谢谢了
...全文
47 点赞 收藏 12
写回复
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
windywalk 2004-01-29
本来就应该是那样的啦,^-^
回复
我的方法不行吗?
回复
chump 2004-01-29
两种方法:
1:insert A select * from B;
zjcxc、giges(giges)等的都可以!
2:insert A values();
declare @code1 as char(4),@code2 as char(4),@code3 as char(4) --具体长度根据表结构

SELECT @code1 =FDCODE2
FROM WHNEC.TBLCS_GENERAL_MASTER
WHERE FDCONTENT = '北京' AND FDCODE1 = '0001'

SELECT @code2 =FDCODE2
FROM WHNEC.TBLCS_GENERAL_MASTER
WHERE FDCONTENT = '华东' AND FDCODE1 = '0002'
SELECT @code3= FDCODE2
FROM WHNEC.TBLCS_GENERAL_MASTER
WHERE FDCONTENT = '受理中心' AND FDCODE1 = '0003'

INSERT INTO WHNEC.TBLCS_SalesDepartment
(FDSALESCODE, FDSALESNAME, FDPROVINCE, FDREGION, FDADDRESS, FDPOST, FDCONTACT, FDTELEPHONE, FDMOBILE, FDFAX, FDEMAIL, FDDEGREE, FDREMARK)
VALUES ('0002','11',@code1,@code2,'','','','','','','',@code3,'')


回复
giggsbj 2004-01-29
INSERT INTO WHNEC.TBLCS_SalesDepartment(FDSALESCODE, FDSALESNAME, FDPROVINCE, FDREGION, FDADDRESS, FDPOST, FDCONTACT, FDTELEPHONE, FDMOBILE, FDFAX, FDEMAIL, FDDEGREE, FDREMARK)
select '0002','11',
(SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '北京' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0001'),
(SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '华东' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0002'),'','','','','','','',
(SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '受理中心' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0003'),''
回复
-狙击手- 2004-01-29
INSERT INTO WHNEC.TBLCS_SalesDepartment(
FDSALESCODE, FDSALESNAME, FDPROVINCE, FDREGION,
FDADDRESS, FDPOST, FDCONTACT, FDTELEPHONE,
FDMOBILE, FDFAX, FDEMAIL, FDDEGREE, FDREMARK
)
select '0002','11',(
SELECT min(WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 )
FROM WHNEC.TBLCS_GENERAL_MASTER
WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '北京'
AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0001'
),(
SELECT min(WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 )
FROM WHNEC.TBLCS_GENERAL_MASTER
WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '华东'
AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0002'
),'','','','','','','',(
SELECT min(WHNEC.TBLCS_GENERAL_MASTER.FDCODE2)
FROM WHNEC.TBLCS_GENERAL_MASTER
WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '受理中心'
AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0003'
),''
回复
windywalk 2004-01-29
INSERT INTO WHNEC.TBLCS_SalesDepartment(FDSALESCODE, FDSALESNAME, FDPROVINCE, FDREGION, FDADDRESS, FDPOST, FDCONTACT, FDTELEPHONE, FDMOBILE, FDFAX, FDEMAIL, FDDEGREE, FDREMARK) select '0002','11',(SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '北京' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0001'),(SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '华东' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0002'),'','','','','','','',(SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '受理中心' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0003'),''
回复
suisuibianbian 2004-01-29
缺少表达式,怎么搞的
回复
--这样写就可以啦:

INSERT INTO WHNEC.TBLCS_SalesDepartment(
FDSALESCODE, FDSALESNAME, FDPROVINCE, FDREGION,
FDADDRESS, FDPOST, FDCONTACT, FDTELEPHONE,
FDMOBILE, FDFAX, FDEMAIL, FDDEGREE, FDREMARK
)
select '0002','11',(
SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2
FROM WHNEC.TBLCS_GENERAL_MASTER
WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '北京'
AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0001'
),(
SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2
FROM WHNEC.TBLCS_GENERAL_MASTER
WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '华东'
AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0002'
),'','','','','','','',(
SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2
FROM WHNEC.TBLCS_GENERAL_MASTER
WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '受理中心'
AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0003'
),''

回复
suisuibianbian 2004-01-29
加了top 1 也还是不行呀
回复
suisuibianbian 2004-01-29
还是说缺少表达式
回复
-狙击手- 2004-01-29
INSERT INTO WHNEC.TBLCS_SalesDepartment(FDSALESCODE, FDSALESNAME, FDPROVINCE, FDREGION, FDADDRESS, FDPOST, FDCONTACT, FDTELEPHONE, FDMOBILE, FDFAX, FDEMAIL, FDDEGREE, FDREMARK) VALUES ('0002','11',(SELECT top 1 WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '北京' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0001'),(SELECT top 1 WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '华东' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0002'),'','','','','','','',(SELECT top 1 WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '受理中心' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0003'),'')
回复
realgz 2004-01-29
可以执行么?
Try:
INSERT INTO WHNEC.TBLCS_SalesDepartment(FDSALESCODE, FDSALESNAME, FDPROVINCE, FDREGION, FDADDRESS, FDPOST, FDCONTACT, FDTELEPHONE, FDMOBILE, FDFAX, FDEMAIL, FDDEGREE, FDREMARK) select '0002','11',(SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '北京' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0001'),(SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '华东' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0002'),'','','','','','','',(SELECT WHNEC.TBLCS_GENERAL_MASTER.FDCODE2 FROM WHNEC.TBLCS_GENERAL_MASTER WHERE WHNEC.TBLCS_GENERAL_MASTER.FDCONTENT = '受理中心' AND WHNEC.TBLCS_GENERAL_MASTER.FDCODE1 = '0003'),''
回复
发动态
发帖子
MS-SQL Server
创建于2007-09-28

3.2w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
社区公告
暂无公告