想要从2003年至今获取价值

时间:2018-07-13 02:34:50

标签: visual-studio-2013 sql-server-2014 ssrs-2012

DECLARE @year VARCHAR(100)

SET @year = '%-2003-%'

SELECT 
    DISTINCT 'AR Invoice', b.user_transaction_type_code as ar_transaction_type_code, b.name_l as ar_name_l, min(transaction_nr) as ar_min_tran_nr, max(transaction_nr) as ar_max_tran_nr, MIN(transaction_text) as min_ar_transaction_text, MAX(transaction_text) as max_ar_transaction_text
FROM
    ar_invoice a, user_transaction_type b
WHERE
    a.user_transaction_type_id = b.user_transaction_type_id AND
    transaction_text like @year
GROUP BY
    b.user_transaction_type_code, b.name_l

我想获取2003年至今的值? 有人可以告诉我怎么做吗?

2 个答案:

答案 0 :(得分:1)

如果要获取2003年至今的值,可以在WHERE子句中使用BETWEEN '2003-01-01' AND GETDATE()选项。

SELECT  DISTINCT 'AR Invoice', b.user_transaction_type_code AS ar_transaction_type_code, 
        b.name_l AS ar_name_l, min(transaction_nr) AS ar_min_tran_nr, max(transaction_nr) AS ar_max_tran_nr, 
        MIN(transaction_text) AS min_ar_transaction_text, MAX(transaction_text) AS max_ar_transaction_text
FROM ar_invoice a
INNER JOIN user_transaction_type b ON b.user_transaction_type_id = a.user_transaction_type_id
WHERE transaction_text BETWEEN '2003-01-01' AND GETDATE()
GROUP BY b.user_transaction_type_code, b.name_l

答案 1 :(得分:0)

DECLARE @year VARCHAR(100)

SET @year = @FromYear --2003-今天

选择不同的“ AR发票”

,b.user_transaction_type_code为ar_transaction_type_code
,b.name_l作为ar_name_l,min(transaction_nr)作为ar_min_tran_nr ,max(transaction_nr)as ar_max_tran_nr ,MIN(transaction_text)作为min_ar_transaction_text ,MAX(transaction_text)作为max_ar_transaction_text

从     ar_invoice a,user_transaction_type b

在哪里     a.user_transaction_type_id = b.user_transaction_type_id 和     transaction_text,例如'%'+'-'+ @year +'-'+'%'

组别     b.user_transaction_type_code,b.name_l