替换 SQL 查询
我想将此查询替换
DECLARE @tmpUser TABLE( UserId INT, UserType INT )
INSERT INTO @tmpUser
SELECT
u.UserId,
1
FROM
Users u (nolock)
WHERE
u.UPIN = @AttendingDoctorID
IF @@ROWCOUNT = 0
BEGIN
INSERT INTO @tmpUser
SELECT
u.UserId,
1
FROM
Users u (nolock)
WHERE
u.FirstName = @AttendingDoctorFirstName AND
u.LastName = @AttendingDoctorLastName
END
SELECT * FROM @tmpUser
为单个 SQL SELECT 语句,而不使用 @tmpUser
或任何其他临时表
I want to replace this Query
DECLARE @tmpUser TABLE( UserId INT, UserType INT )
INSERT INTO @tmpUser
SELECT
u.UserId,
1
FROM
Users u (nolock)
WHERE
u.UPIN = @AttendingDoctorID
IF @@ROWCOUNT = 0
BEGIN
INSERT INTO @tmpUser
SELECT
u.UserId,
1
FROM
Users u (nolock)
WHERE
u.FirstName = @AttendingDoctorFirstName AND
u.LastName = @AttendingDoctorLastName
END
SELECT * FROM @tmpUser
to a single SQL SELECT statement without using @tmpUser
or any other temp tables
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下使用了额外的查找,但它满足您的要求。我不确定这是否比使用临时表更有效,但如果 UPIN 被索引,那么我怀疑它会更有效。
The following uses an extra lookup, but it fulfills your requirements. I don't know for sure if this is any more efficient than using a temp table, though if UPIN is indexed then I suspect it would be.
使用 OR 而不是两个单独的查询怎么样?
我认为这会达到目的。
How about Using OR instead of two separate queries.
I think it would serve the purpose.