如何编写 SQL 语句来比较当前日期和昨天的日期。表具有相同的列。我需要检查所选两个日期在哪一列中的哪些数据不同,并显示两个表之间的更改。
这是我开始的存储过程
CREATE PROCEDURE [dbo].[usp_CompareNetworksandRatings]
@media_month_id smallint,
@rating_category_id tinyint,
@rate_date datetime
AS
BEGIN
SET NOCOUNT ON;
SELECT DISTINCT
nn.nielsen_network_id,
nn.code,
nn.name
FROM
daily_ratings dr (NOLOCK)
JOIN media_months mm (NOLOCK) ON mm.id=dr.media_month_id
AND mm.id=@media_month_id
JOIN uvw_nielsen_network_universes nn (NOLOCK) ON nn.nielsen_network_id=dr.nielsen_network_id
AND nn.start_date<=mm.start_date AND (nn.end_date>=mm.start_date OR nn.end_date IS NULL)
WHERE
dr.rating_category_id=@rating_category_id
AND dr.media_month_id=@media_month_id
AND dr.rating_date=@rate_date
ORDER BY
nn.code