本文介绍了SQL选择查询错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

bscode列是mK_emrcodes表的emrcode的FK

选择查询还试图将NULL插入bscode列,从而返回完整性错误.错误的原因是已知的,但需要将以下选择查询修改为bscode为NULL
的行
有什么建议!!!

The bscode column is FK to emrcode of m_emrcodes table

The select query is also trying to insert NULLs to the bscode column thus returning integrity error. The cause of the error is known but need to modify the below select query to rows having bscode as NULL

Any suggestions!!!

insert into RegClient.DBClient.dbo.m_bscomplaint(bscode,bscomplaintname,normal,responsetype,sortorder,active)
select (select top 1 e_emr.emrcode from RegClient.DBClient.dbo.m_emrcodes e_emr
        inner join RegClient.DBClient.dbo.emrcodes_map map on e_emr.emrcode = map.RegClient_emrcode
        inner join RegServer.DBServer.dbo.m_emrcodes emr on emr.emrcode = map.RegServer_emrcode
        inner join RegServer.DBServer.dbo.m_bscomplaint inst on emr.emrcode = inst.bscode
        Where emr.emrtype in('H','R')
        and e_emr.emrcode = map.RegServer_emrcode
        and map.RegClient_emrcode = e_emr.emrcode
        and e_emr.emrcode in(1041,1060,1150,975,1044,1047,1046,1118,1114,1179,1011,1061,994,1147,1090)
        ) as bscode,temp.bscomplaintname,temp.normal,temp.responsetype,temp.sortorder,temp.active
from RegServer.DBServer.dbo.m_bscomplaint temp

推荐答案

Praveen Chellaboina写道:
Praveen Chellaboina wrote:

任何建议!



使用where子句



Use a where clause


Where bscode is not null 

时,它仍然返回行.那是我的问题,因为查询是用选择查询编写的.

您能详细说明一下吗?

it still returns rows. That is my problem because the query is written in select query.

Could you elaborate it please.


这篇关于SQL选择查询错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 22:19