Tuesday, October 15, 2013

[T-SQL] Query Help

[T-SQL] Query Help


Query Help

Posted: 14 Oct 2013 09:19 AM PDT

drop table #TypeCodecreate table #TypeCode(TypeCodeId int identity(1,1), TypeCode bigint, Name varchar(50))insert into #TypeCode values (3001, 'Loan Type'), (3004, 'Transaction Type'), (3009, 'Event Type'), (3015, 'Participant Type')-- select * from #TypeCodedrop table #LDcreate table #LD(TDID bigint identity(1,1), TranID bigint, LoanID bigint, [Description] varchar(500))insert into #LD values (1234, 5467, 'sdasdas asd asdas'), (1232, 2357, 'nbvnvb vbjjytuytu yt'), (1344, 7989, 'yuimhjkhj'), (1734, 2456, 'retret ghjghjghj'), (1854, 8883, 'ewrgghjg hhgj'), (1784, 2357, 'ytuyu ghjghjghj'), (1284, 9734, 'werewrew ewrwerw')-- select * from #LDdrop table #PDcreate table #PD(PDID bigint, TranID bigint, [Description] varchar(500))insert into #PD values (3456, 1234, 'fghfg fghf hfgh'), (2135, 1234, 'sdjhjk hjkhj khjk'), (7564, 1854, 'wewqg ghjghj hgj')-- select * from #PD drop table #EventLogcreate table #EventLog(EID int, SourceID bigint, SourceType bigint, Description varchar(500))insert into #EventLog values (1, 1234, 3004, 'sadasdadadasfsdfsd fsdfsdf'), -- 3004 means its TranID from #LD (2, 1234, 3004, 'erewrwerwerw '), (3, 1234, 3004, 'erewsfsdf sdfsf sdf '), (4, 5467, 3001, 'ertre rett sdfsf sdf '), -- 3001 means its LoanID from #LD (5, 5467, 3001, 'kljkljkl rett sdfsf sdf '), (6, 3456, 3015, 'utyutyu tyu yutyutuy '), -- 3015 means its PDID from #PD (7, 1784, 3004, 'sadsadasdasd asdasdsad ') Now basically in event log for same transaction id I have different source type id data. I have one store procedure which I pass only #LD TranID and I want it return all event log for all different source type data for that transaction.Like If I pass TranID 1234 sp should return EID 1 to 6

please correct this query where am going wrong

Posted: 14 Oct 2013 11:14 PM PDT

I am trying to add this query in data set. Basically we are using cascading parametersSELECT DISTINCT C.COMPANY_SK,C.COMPANY_DESC FROM DIVISIONMAPPING D INNER JOIN VW_DIM_COMPANY C ON C.COMPANYID=D.COMPANYID WHERE D.ACTIVE IN ('YES','NO') AND (D.BUSINESSDIVISION in @Division OR @Division in ( 'All')) AND D.EXCLUDEFLAG=0ORDER BY COMPANY_DESC ASCplease correct me regarding this issue

display 12 month list through query

Posted: 14 Oct 2013 04:34 PM PDT

Hi All,I am havinfg a column in a table which store a date. say for eg birthDate. I want to display count monthwise.But in case if there is no birthday falls in March Month then i need to display column header as 3 and under that 0 (zero) count. Can you please suggest any idea.ThanksAbhas.

sorting by month with current month at top

Posted: 14 Oct 2013 07:39 AM PDT

HiIn one of my query I need data to be sorted starting with current month. Here is sample script:create table OrderTest(OrderDate datetime,orderCount int)GOinsert into OrderTest values('2013/10/15',30)insert into OrderTest values('2013/10/17',40)insert into OrderTest values('2013/09/13',60)insert into OrderTest values('2013/08/21',45)insert into OrderTest values('2013/07/13',38)insert into OrderTest values('2013/06/15',23)insert into OrderTest values('2013/05/15',56)insert into OrderTest values('2013/04/15',267)insert into OrderTest values('2013/03/19',67)insert into OrderTest values('2013/02/15',45)insert into OrderTest values('2013/01/15',90)insert into OrderTest values('2012/11/15',22)insert into OrderTest values('2012/12/15',76)GOselect datepart(mm,OrderDate) MonthNum,AVG(orderCount) AvgOrderCountFROM OrderTestGROUP BY datepart(mm,OrderDate)Order BY datepart(mm,OrderDate)I need data like:10 3011 2212 761 902 453 674 2675 566 237 388 459 60thanks

No comments:

Post a Comment

Search This Blog