Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
T-SQL (SS2K8)
»
TSQL Query help
TSQL Query help
Rate Topic
Display Mode
Topic Options
Author
Message
komal145
komal145
Posted Monday, January 28, 2013 10:03 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Tuesday, March 19, 2013 1:38 PM
Points: 168,
Visits: 540
I have table from November with the flag 'N' and 'Y'
,when I get the laons for december , need to get the count of laons in november , i.e include all loans from
november with flag='N' in december.
Please find the example below.
---november------------
drop table #temp
Create table #Temp
(
Loan
,varchar(5)
,Month varchar(20)
,flag char(1))
INSERT INTO #Temp values('1234','november','N')
INSERT INTO #Temp values ('3241','November','N')
INSERT INTO #Temp values ('4235','November','N')
INSERT INTO #Temp values ('3214','November','N')
INSERT INTO #Temp values ('3456','November','Y')
----DECEMBER------------
Drop table #temp1
Create table #Temp1
(
Loan varchar(5)
,Month varchar(20)
,flag char(1))
INSERT INTO #Temp1 values ('4321','december','N')
INSERT INTO #Temp1 values ('4324','december','N')
---Since the flag is 'N' all the loans in november, these loans should be included into december'
----RESULT oF FINAL TABLE FOR DECEMBER----
INSERT INTO #Temp1 values('1234','November','N')
INSERT INTO #Temp1 values ('3241','November','N')
INSERT INTO #Temp1 values ('4235','November','N')
INSERT INTO #Temp1 values ('3214','November','N')
INSERT INTO #Temp1 values ('4321','december','N')
INSERT INTO #Temp1 values ('4324','december','N')
Post #1412525
Sean Lange
Sean Lange
Posted Monday, January 28, 2013 10:26 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 2:33 PM
Points: 8,620,
Visits: 8,261
Nice job creating ddl and sample data.
Unfortunately your data and your description appear to be out of synch with each other. In your desired output table you have loans that don't exist in the #Temp table. If you can explain your situation a little better we can help.
And as a suggestion you should avoid using reserved words like Month as a column name. Not only does it make querying a little more difficult it is totally ambiguous what it means. Same thing with a column named "Flag". What does that mean?
_______________________________________________________________
Need help? Help us help you.
Read the article at
http://www.sqlservercentral.com/articles/Best+Practices/61537/
for best practices on asking questions.
Need to split a string? Try Jeff Moden's
splitter
.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1412546
komal145
komal145
Posted Monday, January 28, 2013 10:26 AM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Tuesday, March 19, 2013 1:38 PM
Points: 168,
Visits: 540
NO Problem.I got it.
Post #1412547
Sean Lange
Sean Lange
Posted Monday, January 28, 2013 10:38 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Today @ 2:33 PM
Points: 8,620,
Visits: 8,261
komal145 (1/28/2013)
NO Problem.I got it.
As in you figured out your query or you understood my suggestion?
_______________________________________________________________
Need help? Help us help you.
Read the article at
http://www.sqlservercentral.com/articles/Best+Practices/61537/
for best practices on asking questions.
Need to split a string? Try Jeff Moden's
splitter
.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Post #1412551
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.