如何检查,如果列值不为空,则使用等号,否则忽略过滤器 [英] How Do I Check , If Column Value Is Not Null, Then Use Equal Sign, Else Ignore The Filter
问题描述
大家好,
i有一个简单的问题,但无法解决,你的帮助将受到高度赞赏...
let我解释一下这个问题....
i有两张桌子,
表1:KPI_ID,单位,频率,
表2:KPI_ID,Value,ValueDate。(值日期格式为20140131)
i连接KPI ID上的表,并在GridView中显示结果。在这里工作
在SQL视图中说几条记录,
KPI_ID,单位,频率,价值,Value_Date
1,1001,15,15,55,20140131
2,1002,10,15,50,20140131
3,1002,10,15,54,20140231
4,1003,10,15,53,20140131
5,1003,10 ,15,57,20140228
6,1004,10,15,null,null
7,1005,10,15,null,null
8,1006,10,15,null,null
当我将过滤器应用为2014年1月时,它会显示我的记录编号。 1,2,4 ..
但我希望看到记录编号,1,2,3,4,5和6,7,8
>
当我将过滤器应用为2014年FEB时,它仅向我显示3号和5号记录,但我希望看到
所有记录,WHICH记录没有FEB 2014的值,应该来....
如何获得.....
如何实现这一目标。 ..?
请....
如果列值为NULL且仍然需要获取它然后使用左外连接。
但是我无法理解如果你把过滤器2014年2014年,那么你如何期待所有记录? 1,2,3,4,5和6,7,8
如果您使用Left outer Join,那么您将获得记录:1,2,4,6 ,7,8
旧解决方案:
创建 < span class =code-keyword> table A
(
KPI_ID Int ,
单位 decimal ,
频率 decimal ,
)
创建 表 B
(
KPI_ID Int ,
值十进制,
ValueDate 日期时间,
)
- 请插入您想要的值
- 现在运行如下查询
select * 来自 A ta left join B tb ta.KPI_ID = tb.KPI_ID
更新后的解决方案:
创建 table table1
(
KPI_ID Int ,
单位十进制,
频率十进制,
)
创建 table table2
(
KPI_ID Int ,
Value decimal ,
ValueDate 日期时间,
)
选择 * 来自 table1
Go
选择 *来自 table1
Go
将 插入 table1(KPI_ID,单位,频率)值( 1001 , 10 , 15 )
将 插入 table1(KPI_ID,单位,频率)值( 1002 , 10 , 15 )
将 插入 table1(KPI_ID,单位,频率)值( 1003 , 10 , 15 )
将 插入 table1(KPI_ID,单位,频率)值( 1004 , 10 , 15 )
将 插入 table1(KPI_ID,单位,频率)值( 1005 , 10 , 15 )
插入 into table1(KPI_ID,单位,频率)值( 1006 , 10 , 15 )
插入 进入 table1(KPI_ID,单位,频率)值( 1007 , 10 , 15 )
GO
将 插入 table2(KPI_ID,Value,ValueDate)值( 1001 , 55 ,' 20140131')
插入 into table2(KPI_ID,Value,ValueDate) values ( 1002 , 50 ,' 20140131')
将 插入 table2(KPI_ID,Value,ValueDate)值( 1002 , 54 ,' 20140228')
插入 into table2(KPI_ID,Value,ValueDate) values ( 1003 , 53 ,' 20140131')
将 插入 table2(KPI_ID,Value,ValueDate)值( 1003 , 57 ,' 20140228')
GO
- 1,1001,1,10,15,55,20140131
- 2,1002,10,15,50,20140131
- 3,1002,10,15,54,20140231
- 4,100 3,10,15,53,20140131
- 5,1003,10,15 ,57,20140228
- 6,1004,10,15,null,null
- 7,1005,10,15,null,null
- 8,1006,10,15,null,null
- 请插入您想要的值
- 现在运行如下查询
选择 * 来自 table1 ta left join table2 tb ta.KPI_ID = tb.KPI_ID WHERE CONVERT (<跨度cl ass =code-keyword> VARCHAR ( 24 ),tb.ValueDate, 112 )喜欢 ' 201401%' OR CONVERT ( VARCHAR ( 24 ),tb.ValueDate, 112 ) IS NULL 跨度>
Hi Guys,
i have a simple problem, but unable to solve, your help would be highly appreciated...
let me explain the problem....
i have two tables,
Table 1: KPI_ID, Unit, Frequency,
Table 2 : KPI_ID, Value, ValueDate.(Value Date format is 20140131)
i joined tables on KPI ID, AND showing result in GridView. working up to here
let say few records in SQL View,
KPI_ID, Unit, Frequency, Value, Value_Date
1, 1001, 10, 15, 55, 20140131
2, 1002, 10, 15, 50, 20140131
3, 1002, 10, 15, 54, 20140231
4, 1003, 10, 15, 53, 20140131
5, 1003, 10, 15, 57, 20140228
6, 1004, 10, 15, null, null
7, 1005, 10, 15, null, null
8, 1006, 10, 15, null , null
when i apply filter as JAN 2014, it shows me records number. 1, 2, 4..
but i want to see record number,, 1, 2, 3,4, 5 and 6, 7, 8
WHEN i apply filter as FEB 2014, it shows me only record number 3 and 5 , but i want to see
all records, WHICH record does not have value for FEB 2014 , should come....
how to get.....
how to achieve this...?
Please....
If Column value is NULL and still you want to fetch it then use left outer join.
But I am not able to understand If you put Filter JAN 2014 then how you are expecting all records ?? 1,2,3,4,5 and 6, 7, 8
If you use Left outer Join then you will get Records : 1,2,4,6,7,8
OLD Solution:
Create table A ( KPI_ID Int, Unit decimal, Frequency decimal, ) Create table B ( KPI_ID Int, Value decimal, ValueDate Datetime, ) -- Please insert the value you want -- Now run the query as below select * from A ta left join B tb on ta.KPI_ID = tb.KPI_ID
Updated Solution:
Create table table1 ( KPI_ID Int, Unit decimal, Frequency decimal, ) Create table table2 ( KPI_ID Int, Value decimal, ValueDate Datetime, ) select * from table1 Go select * from table1 Go Insert into table1 (KPI_ID, Unit, Frequency)values(1001, 10, 15) Insert into table1 (KPI_ID, Unit, Frequency)values(1002, 10, 15) Insert into table1 (KPI_ID, Unit, Frequency)values(1003, 10, 15) Insert into table1 (KPI_ID, Unit, Frequency)values(1004, 10, 15) Insert into table1 (KPI_ID, Unit, Frequency)values(1005, 10, 15) Insert into table1 (KPI_ID, Unit, Frequency)values(1006, 10, 15) Insert into table1 (KPI_ID, Unit, Frequency)values(1007, 10, 15) GO Insert into table2 (KPI_ID, Value, ValueDate)values(1001, 55, '20140131') Insert into table2 (KPI_ID, Value, ValueDate)values(1002, 50, '20140131') Insert into table2 (KPI_ID, Value, ValueDate)values(1002, 54, '20140228') Insert into table2 (KPI_ID, Value, ValueDate)values(1003, 53, '20140131') Insert into table2 (KPI_ID, Value, ValueDate)values(1003, 57, '20140228') GO --1, 1001, 10, 15, 55, 20140131 --2, 1002, 10, 15, 50, 20140131 --3, 1002, 10, 15, 54, 20140231 --4, 1003, 10, 15, 53, 20140131 --5, 1003, 10, 15, 57, 20140228 --6, 1004, 10, 15, null, null --7, 1005, 10, 15, null, null --8, 1006, 10, 15, null , null -- Please insert the value you want -- Now run the query as below select * from table1 ta left join table2 tb on ta.KPI_ID = tb.KPI_ID WHERE CONVERT(VARCHAR(24),tb.ValueDate,112) like '201401%' OR CONVERT(VARCHAR(24),tb.ValueDate,112) IS NULL
这篇关于如何检查,如果列值不为空,则使用等号,否则忽略过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!