-4
Date         Amount     name of date
2017-09-05   364100.00  Tuesday 
2017-09-11   189700.00  Monday

Tuesday should have value as 364100+189700

1
  • 1
    Is this a question? Commented Sep 19, 2017 at 22:00

2 Answers 2

0

Question is badly worded, but I only take a guess this is what you are after??

    ;with mycte as (
select
'2017-09-05' as date
, 364100.00 as amount
 ,'Tuesday' as [name of date]

 union all 
 select
  '2017-09-11'
  , 189700.00
  ,' Monday'
  )

  Select 
  date
  ,amount
  ,[name of date]
  ,SUM(amount) over (order by date) as Total
   from mycte

   order by date
Sign up to request clarification or add additional context in comments.

1 Comment

0

To combine 2 integer, you need convert each as varchar first then you can use operator + or use concat function like this :

SELECT CONCAT(CAST(364100 AS varchar(20)), '+', CAST(189700 AS varchar(20)))

But to achieve your goal, because a row depends on other row, may be you need cursor for looping like this :

DECLARE @Your_Table TABLE
(
    Date_Column Date,
    Amount INT
)

DECLARE @ResultTable TABLE
(
    Date_Column Date,
    Amount VarChar(200),
    NameOfDate VarChar(20)
)

INSERT INTO @Your_Table VALUES('2017-09-05', 364100);
INSERT INTO @Your_Table VALUES('2017-09-11', 189700);

DECLARE @Dt Date, @Am INT, @CurrentAm VarChar(200)
SELECT @CurrentAm = '';

DECLARE db_cursor CURSOR FOR  
SELECT * FROM @Your_Table ORDER BY Date_Column DESC

OPEN db_cursor   
FETCH NEXT FROM db_cursor INTO @Dt, @Am

WHILE @@FETCH_STATUS = 0   
BEGIN   
        IF @CurrentAm=''
        BEGIN
            SELECT @CurrentAm=CAST(@Am AS VarChar(200));
            INSERT INTO @ResultTable VALUES(@Dt,@CurrentAm, DATENAME(DW, @Dt));
        END
        ELSE
        BEGIN
            SELECT @CurrentAm=CONCAT(CAST(@Am AS varchar(20)), '+', CAST(@CurrentAm AS VarChar(200)));
            INSERT INTO @ResultTable VALUES(@Dt,@CurrentAm, DATENAME(DW, @Dt));
        END

       FETCH NEXT FROM db_cursor INTO @Dt, @Am
END   

CLOSE db_cursor   
DEALLOCATE db_cursor

SELECT * FROM @ResultTable ORDER BY Date_Column

Edited : AS Harry's comment, You do not have to convert int to char in concat function

replace this

SELECT @CurrentAm=CONCAT(CAST(@Am AS varchar(20)), '+', CAST(@CurrentAm AS VarChar(200)));

with this

SELECT @CurrentAm=CONCAT(@Am, '+', @CurrentAm);

1 Comment

Talk about literal answer to the ops question.. but your guess at what the OP wants is as good as any.. BTW, You do not have to convert int to char before you use concat select concat(12345,'+',6789) plus_sign, concat(12345,6789) no_plus_sign

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.