15,890,579 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Shivam Chinna 2022 (Top 7 by date)
Shivam Chinna 2022
21-Jul-22 4:40am
View
should we use cursors to update the result set for by the above-mentioned update trigger requirement?
Shivam Chinna 2022
21-Jul-22 3:24am
View
select TransactionNumber, acid , tm.USERID,designation ,count(*) as nooftrans from TransactionMaster tm join usermaster um
on tm.userid = um.USERID
where datediff(dd,dot,getdate()) = 0 and um.designation = 'T'
group by TransactionNumber, ACID,tm.USERID ,Designation
order by ACID
Is this query correct to get whether the transaction was done by the teller or not?
Shivam Chinna 2022
21-Jul-22 2:24am
View
This is not an assignment for grades. I'm a freelancer from a non-IT background learning SQL server for free from SQL server videos shared by my friend because I can't afford the training fee. in those videos, triggers are missing, and now facing trouble implementing them practically. Just learning SQL to upgrade my skills for better opportunities. Any help would be much appreciated.
Shivam Chinna 2022
19-Jul-22 7:50am
View
No worries CHill60 I got it. Thanks for your help I'm able to get my desired output now with your idea. Thanks a lot, you made my day.
Shivam Chinna 2022
19-Jul-22 6:57am
View
Why I'm using a while loop is to print each row value by storing each row value into variables and then printing them in a report format. without the while loop how can I print the resultset from the temp table. You can see I'm iterating while loop until the @count times i.e., no of rows fetched and each row I'm storing and printing for output.
Shivam Chinna 2022
18-Jul-22 13:09pm
View
_This is the output I'm getting __________________________________________________________________________________
SL.No DOT TXN_TYPE Cheque_No Amount RunningBalance
_______________________________________________________________________
1 Nov 13, 2021 cqd 50 84790.00 84790.00
2 Nov 28, 2021 cw 28 -59415.00 -59415.00
3 Jun 22, 2022 cqd 12 191785.00 191785.00
Shivam Chinna 2022
18-Jul-22 13:06pm
View
Deleted
Hi CHILL60 I appreciate your time and effort. thank you. Your solution works fine for my desired output. But when I try the same logic in my stored proc I'm not getting the same output. I'll post you my proc can you troubleshoot my mistakes.
alter proc usp_PreviousMonthBankStmt
(
@acid int = 1
)
as
begin
-- set nocount on will remove the sql messages
set nocount on
declare @CustomerName varchar(40)
declare @pid char(2)
declare @brid char(3)
declare @cbalance money
declare @RNO int
declare @DOT datetime
declare @TXN_TYPE char(3)
declare @CHQ_NO int
declare @TXN_AMOUNT money
declare @Running_TXN_AMOUNT money
declare @lastmonth varchar(20)
declare @lastmonthshort varchar(20)
declare @TodaysDate datetime
declare @LastMonthEndDate datetime
set @TodaysDate = GETDATE()
-- get the last month name
select @lastmonth = DATENAME(mm,dateadd(mm,-1,@TodaysDate))
-- get short form of month name
select @lastmonthshort = SUBSTRING(@lastmonth,1,3)
-- gets me last date of previous month
select @LastMonthEndDate = EOMONTH(dateadd(mm,-1,@TodaysDate))
print '----------------------------------------------------------------------------------'
print ' Indian Bank '
print ' List of Transactions from '+@lastmonthshort + ' 1 to '+ convert(varchar,@LastMonthEndDate,107)+ ' Report'
print '----------------------------------------------------------------------------------'
-- 1: Get the customer info
select @CustomerName = name,
@brid = brid,
@pid = pid,
@cbalance = clearbalance
from AccountMaster where acid = @acid
-- 2: Print the variables
Print 'Product Name :'+@pid
Print 'Account No :'+cast(@acid as varchar) +space(10)+' Branch :'+@brid
print 'Customer Name :'+@CustomerName +space(10)+'Clear Balance :'+cast(@cbalance as varchar)+' INR'
print'___________________________________________________________________________________'
print'SL.No DOT TXN_TYPE Cheque_No Amount RunningBalance'
print'___________________________________________________________________________________'
-- 3: Get previous year txns for the given customer
select ROW_NUMBER() over (order by DOT asc) as RNO, DOT, TXN_TYPE, CHQ_NO,
case WHEN TXN_TYPE = 'CW' THEN (-1) * TXN_AMOUNT ELSE TXN_AMOUNT END AS TXN_AMOUNT
into #TxnData
from TransactionMaster
where datediff(YY,dot,getdate()) <= 2 and acid = @acid
-- 4: Print the data from temp table
--select * from #TxnData
-- 5: Loop
declare @x int
set @x = 1
declare @count int
-- Condition
select @count = count(*) from #TxnData
-- loop syntax
while( @x <= @count )
begin
select @RNO = RNO,
@DOT = DOT,
@TXN_TYPE = TXN_TYPE,
@CHQ_NO = CHQ_NO,
@TXN_AMOUNT = TXN_AMOUNT,
--@Running_TXN_AMOUNT = sum(TXN_AMOUNT) over (order by RNO)
from #TxnData where RNO = @x
-- print the data
print cast(@RNO as varchar) + space(8) + convert(varchar, @DOT, 107) + space(7) +
@TXN_TYPE + space(8) + cast(isnull(@CHQ_NO,0) as varchar) + space(8) + cast(@TXN_AMOUNT as varchar)+ space(8)+cast(sum(TXN_AMOUNT) over (order by RNO) as varchar)
-- incr
set @x = @x + 1
end --- loop end
print '____________________________________________________________________________________'
print 'Total no of transactions :' +cast(@count as varchar)
declare @CDs int
select @CDs = count(*) from #TxnData where TXN_TYPE = 'CD'
print ' Cash Deposits :'+ cast(@CDs as varchar)
declare @CWs int
select @CWs = count(*) from #TxnData where TXN_TYPE = 'CW'
print ' Cash Withdrawals :'+ cast(@CWs as varchar)
declare @CQDs int
select @CQDs = count(*) from #TxnData where TXN_TYPE = 'CQD'
print ' Cheque Deposits :'+ cast(@CQDs as varchar)
print '____________________________________________________________________________________'
print '____________________________________________________________________________________'
end
go
e
Show More