匹配记录转到一个临时表,没有匹配到另一个 [英] Matching Records Go To One Temp Table, No Matches To Another

查看:84
本文介绍了匹配记录转到一个临时表,没有匹配到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。 这是我在这个论坛上的第一篇文章,所以我希望我在正确的位置。

Hello everyone.  This is my first post on this forum, so I hope I am in the right place.

我试图想办法编写一个查看记录集的TSQL查询,匹配找到一个临时表,而不匹配则转到另一个临时表。 类似于 

I am trying to figure out a way to write a TSQL query that looks at a recordset, and matches found go to one temp table, while non-matches go to another.  Something like 

如果OBJECT_ID('tempdb .. #tbl_a')不是null drop table #tbl_a

SELECT * INTO  #tbl_a FROM(

If OBJECT_ID('tempdb..#tbl_a') is not null drop table #tbl_a
SELECT * INTO  #tbl_a FROM (

然后你的带有标准的select语句)a

then your select statement with criteria ) a

ELSE

与另一个不匹配临时表

谢谢:)

Robert

推荐答案

创建表#Table(Id int,Name Varchar(100))

Go¥
如果Object_ID('TempDb.dbo。#Table')不为空

开始 

选择'对象存在'
结束

否则

开始

选择"对象不存在"

结束

Drop Table #Table
Create Table #Table (Id int, Name Varchar(100))
Go
If Object_ID('TempDb.dbo.#Table') is not null
Begin 
Select 'Object Exists'
End
Else
Begin
Select 'Object Not Exists'
End
Drop Table #Table


这篇关于匹配记录转到一个临时表,没有匹配到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆