【发布时间】:2019-06-20 13:43:09
【问题描述】:
如果此查询返回值,我需要返回 true,(并且它在 db 中有值)
SELECT * from AllMembers a
join Cards c on c.IDMember = a.MemberID
where LEN(a.EmployeeNum) = 9
and LEFT(c.CardNumber,3) = '777'
and a.Email is not null
and a.LastUpdate > DATEADD(YEAR, -1 , GETDATE())
and c.CardStatus = 1
and c.AddedTime > DATEADD(YEAR, -1 , GETDATE())
or
LEN(a.EmployeeNum) = 9
and LEFT(c.CardNumber,4) = '2010'
and a.Email is not null
and a.LastUpdate > DATEADD(YEAR, -1 , GETDATE())
and c.CardStatus = 1
and c.AddedTime > DATEADD(YEAR, -1 , GETDATE())
但是写这个值返回false,为什么?
string Query= string.Format(@"use Knowledge4All
IF EXISTS (
SELECT ID FROM {0}..AllMembers
JOIN Cards where IDMember = @memberID
and (where LEN(EmployeeNum) = 9
and LEFT(CardNumber,3) = '777'
and Email is not null
and LastUpdate > DATEADD(YEAR, -1 , GETDATE())
and CardStatus = 1
and AddedTime > DATEADD(YEAR, -1 , GETDATE())))
select 1
OR
IF exists(
(LEN(EmployeeNum) = 9
and LEFT(CardNumber,4) = '2010'
and Email is not null
and LastUpdate > DATEADD(YEAR, -1 , GETDATE())
and CardStatus = 1
and AddedTime > DATEADD(YEAR, -1 , GETDATE()) )
SELECT 1", DbName);
我写错了吗?朗姆酒最好的理由是什么?
【问题讨论】:
-
为什么要在查询开头加上use KnowledgeAll?您是否连接到不同的数据库?
-
@Steve 是的,这是个错误
-
我认为你的问题在这里
{0}..AllMembers你有太多的点(。),应该{0}.AllMembers -
@styx 该语法用于选择默认架构。例如,如果默认架构是 dbo,那么这将等同于
.dbo.AllMembers.
标签: c# mysql sql-server