Leaderboard command for leveling system? - discord.py rewrite - discord

So, me and a friend have worked on a level leaderboard command. Here's the code.
#commands.command()
async def leaderboard(self, ctx):
with open('level.json', 'r') as fp:
users = json.load(fp)
high_score_list = sorted(users, key=lambda x : users[x].get('level', 0), reverse=True)
message = ''
for number, user in enumerate(high_score_list):
message += '{0}. {1} with {2}level\n'.format(number + 1,user, users[user].get('level', 0))
await ctx.send('{}'.format(high_score_list))
But, to our surprise, this showed up.
['550912080627236874', '499454400994082826', '578729911284400138', '757122465687273525', '726314322565005382', '472984563447103518', '159985870458322944', '746515506688688178', '733012127576490165', '754945861112430693', '750960499063259196', '359550695042711552', '575252669443211264', '553292456226062367', '744117280312393769']
['578729911284400138', '726314322565005382', '550912080627236874', '359550695042711552', '472984563447103518', '750960499063259196', '159985870458322944', '499454400994082826', '757122465687273525', '553292456226062367', '746515506688688178', '575252669443211264', '733012127576490165', '754945861112430693', '744117280312393769']
['578729911284400138', '726314322565005382', '550912080627236874', '359550695042711552', '472984563447103518', '750960499063259196', '159985870458322944', '499454400994082826', '757122465687273525', '553292456226062367', '746515506688688178', '575252669443211264', '733012127576490165', '754945861112430693', '744117280312393769']
['578729911284400138', '726314322565005382', '550912080627236874', '359550695042711552', '472984563447103518', '750960499063259196', '159985870458322944', '499454400994082826', '757122465687273525', '553292456226062367', '746515506688688178', '575252669443211264', '733012127576490165', '754945861112430693', '744117280312393769']
['578729911284400138', '726314322565005382', '550912080627236874', '359550695042711552', '472984563447103518', '750960499063259196', '159985870458322944', '499454400994082826', '757122465687273525', '553292456226062367', '746515506688688178', '575252669443211264', '733012127576490165', '754945861112430693', '744117280312393769']
['578729911284400138', '726314322565005382', '550912080627236874', '359550695042711552', '472984563447103518', '750960499063259196', '159985870458322944', '499454400994082826', '757122465687273525', '553292456226062367', '746515506688688178', '575252669443211264', '733012127576490165', '754945861112430693', '744117280312393769']
It showed up repeatedly, really.
How do we make it so that what shows up is the names on a leaderboard-like form? Thanks!

Related

How to fix 'selectionListener="#{bindings.xList.collectionModel.makeCurrent}": java.lang.NullPointerException' error in ADF

Sometimes, the user is getting the error :
java.lang.NullPointerException at oracle.jbo.uicli.binding.JUCtrlHierBinding.bringNodeToRangeKeyPath(JUCtrlHierBinding.java:1513).
I set "oracle.jbo" & "oracle.adfinternal" Finest as mentioned by Mr. MrAdibou, in a comment on similar error, I was able to see below detailed error. To note that I am not able to reproduce the scenario, and the user is facing the error randomly.
[AdminServer] [ERROR] [] [oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter] [host: WebHyperV] [nwaddr: xxx.xxx.xx.xxx] [tid: [ACTIVE].ExecuteThread: '6' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: WD] [ecid: aa53c714-24a8-4304-a637-d8f3525c2c84-00001169,0] [APP: EmpApp] [partition-name: DOMAIN] [tenant-name: GLOBAL] [DSID: 0000MfQDj1r0ZrwN0EFg6F1SsltU00000k] [LOG_FILE: C:\Oracle\Middleware\Oracle_Home_12213\user_projects\domains\base_domain\servers\AdminServer\logs\AdminServer-diagnostic.log] ADF_FACES-60096:Server Exception during PPR, #3[[
javax.el.ELException: /WEB-INF/com/rs/emp/fragments/EmployeeView.jsff #513,111 selectionListener="#{bindings.employeeList.collectionModel.makeCurrent}": java.lang.NullPointerException
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
at org.apache.myfaces.trinidad.component.UIXComponentBase.broadcastToMethodExpression(UIXComponentBase.java:2032)
at org.apache.myfaces.trinidad.component.UIXTable.broadcast(UIXTable.java:278)
at oracle.adf.view.rich.component.UIXTable.broadcast(UIXTable.java:100)
at oracle.adf.view.rich.component.rich.data.RichTable.broadcast(RichTable.java:126)
at org.apache.myfaces.trinidad.component.UIXComponent.broadcastInContext(UIXComponent.java:364)
at org.apache.myfaces.trinidad.component.WrapperEvent.broadcastWrappedEvent(WrapperEvent.java:82)
at org.apache.myfaces.trinidad.component.UIXCollection.broadcast(UIXCollection.java:195)
at org.apache.myfaces.trinidad.component.UIXTable.broadcast(UIXTable.java:281)
at oracle.adf.view.rich.component.UIXTable.broadcast(UIXTable.java:100)
at oracle.adf.view.rich.component.rich.data.RichTable.broadcast(RichTable.java:122)
at org.apache.myfaces.trinidad.component.UIXComponent.broadcastInContext(UIXComponent.java:364)
at org.apache.myfaces.trinidad.component.WrapperEvent.broadcastWrappedEvent(WrapperEvent.java:82)
at org.apache.myfaces.trinidad.component.UIXCollection.broadcast(UIXCollection.java:176)
at org.apache.myfaces.trinidad.component.UIXTable.broadcast(UIXTable.java:281)
at oracle.adf.view.rich.component.UIXTable.broadcast(UIXTable.java:100)
at oracle.adf.view.rich.component.rich.data.RichTable.broadcast(RichTable.java:126)
at org.apache.myfaces.trinidad.component.UIXComponent.broadcastInContext(UIXComponent.java:364)
at org.apache.myfaces.trinidad.component.WrapperEvent.broadcastWrappedEvent(WrapperEvent.java:82)
at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent$1.run(ContextSwitchingComponent.java:168)
at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent._processPhase(ContextSwitchingComponent.java:510)
at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent.broadcast(ContextSwitchingComponent.java:171)
at org.apache.myfaces.trinidad.component.UIXComponent.broadcastInContext(UIXComponent.java:364)
at org.apache.myfaces.trinidad.component.WrapperEvent.broadcastWrappedEvent(WrapperEvent.java:82)
at oracle.adf.view.rich.component.fragment.UIXInclude.broadcast(UIXInclude.java:111)
at org.apache.myfaces.trinidad.component.UIXComponent.broadcastInContext(UIXComponent.java:364)
at org.apache.myfaces.trinidad.component.WrapperEvent.broadcastWrappedEvent(WrapperEvent.java:82)
at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent$1.run(ContextSwitchingComponent.java:168)
at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent._processPhase(ContextSwitchingComponent.java:510)
at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent.broadcast(ContextSwitchingComponent.java:171)
at oracle.adf.view.rich.component.fragment.UIXInclude.broadcast(UIXInclude.java:115)
at org.apache.myfaces.trinidad.component.UIXComponent.broadcastInContext(UIXComponent.java:364)
at org.apache.myfaces.trinidad.component.WrapperEvent.broadcastWrappedEvent(WrapperEvent.java:82)
at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent$1.run(ContextSwitchingComponent.java:168)
at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent._processPhase(ContextSwitchingComponent.java:510)
at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent.broadcast(ContextSwitchingComponent.java:171)
at org.apache.myfaces.trinidad.component.UIXComponent.broadcastInContext(UIXComponent.java:364)
at org.apache.myfaces.trinidad.component.WrapperEvent.broadcastWrappedEvent(WrapperEvent.java:82)
at oracle.adf.view.rich.component.fragment.UIXInclude.broadcast(UIXInclude.java:111)
at org.apache.myfaces.trinidad.component.UIXComponent.broadcastInContext(UIXComponent.java:364)
at org.apache.myfaces.trinidad.component.WrapperEvent.broadcastWrappedEvent(WrapperEvent.java:82)
at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent$1.run(ContextSwitchingComponent.java:168)
at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent._processPhase(ContextSwitchingComponent.java:510)
at oracle.adf.view.rich.component.fragment.ContextSwitchingComponent.broadcast(ContextSwitchingComponent.java:171)
at oracle.adf.view.rich.component.fragment.UIXInclude.broadcast(UIXInclude.java:115)
at org.apache.myfaces.trinidad.component.UIXComponent.broadcastInContext(UIXComponent.java:364)
at oracle.adf.view.rich.event.ProxyEvent.broadcastWrappedEvent(ProxyEvent.java:72)
at oracle.adf.view.rich.component.fragment.UIXRegion._handleProxyEvent(UIXRegion.java:933)
at oracle.adf.view.rich.component.fragment.UIXRegion.broadcast(UIXRegion.java:117)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._invokeApplication(LifecycleImpl.java:1243)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executeInvokeApplication(LifecycleImpl.java:686)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:364)
at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:227)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:650)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:207)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:105)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:529)
at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:529)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:354)
at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:232)
at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:169)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
at oracle.security.jps.ee.http.JpsAbsFilter$3.run(JpsAbsFilter.java:172)
at java.security.AccessController.doPrivileged(Native Method)
at oracle.security.jps.util.JpsSubject.doAsPrivileged(JpsSubject.java:315)
at oracle.security.jps.ee.util.JpsPlatformUtil.runJaasMode(JpsPlatformUtil.java:650)
at oracle.security.jps.ee.http.JpsAbsFilter.runJaasMode(JpsAbsFilter.java:110)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilterInternal(JpsAbsFilter.java:273)
at oracle.security.jps.ee.http.JpsAbsFilter.doFilter(JpsAbsFilter.java:147)
at oracle.security.jps.ee.http.JpsFilter.doFilter(JpsFilter.java:94)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
at oracle.dms.servlet.DMSServletFilter.doFilter(DMSServletFilter.java:248)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:32)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3701)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3667)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326)
at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)
at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2443)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2291)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2269)
at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1703)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1663)
at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:272)
at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:352)
at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:337)
at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:57)
at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:644)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:415)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:355)
Caused by: java.lang.NullPointerException
at oracle.jbo.uicli.binding.JUCtrlHierBinding.bringNodeToRangeKeyPath(JUCtrlHierBinding.java:1513)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding.bringNodeToRangeKeyPath(FacesCtrlHierBinding.java:123)
at oracle.adfinternal.view.faces.model.binding.RowDataManager.setRowKey(RowDataManager.java:152)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding$FacesModel.setRowKey(FacesCtrlHierBinding.java:932)
at oracle.adfinternal.view.faces.model.binding.FacesBindingUtils.pushCurrencyToModel(FacesBindingUtils.java:25)
at oracle.adfinternal.view.faces.model.binding.FacesCtrlHierBinding$FacesModel.makeCurrent(FacesCtrlHierBinding.java:779)
at sun.reflect.GeneratedMethodAccessor813.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
... 105 more
]]
table code:
<af:table value="#{bindings.employeeList.collectionModel}"
var="row" editingMode="clickToEdit"
rows="#{bindings.employeeList.rangeSize}"
emptyText="#{bindings.employeeList.viewable ? 'No data to display.' : 'Access Denied.'}"
rowBandingInterval="0"
columnStretching="#{bindings.employeeList.estimatedRowCount==0 ? 'last' : 'multiple'}"
selectedRowKeys="#{bindings.employeeList.collectionModel.selectedRow}"
selectionListener="#{bindings.employeeList.collectionModel.makeCurrent}"
rowSelection="single"
rendered="#{viewScope.crud.crudMode ne 'empty'}"
binding="#{viewScope.crud.tblPS}" varStatus="vs"
id="t36" fetchSize="10"
blockRowNavigationOnError="always"
contentDelivery="immediate" scrollPolicy="page">
<af:column width="6%" headerText="code"
id="c251">
<af:outputText value="#{row.bindings.code.inputValue}"
id="it115"/>
</af:column>
<af:column width="21%"
headerText="name" id="c252">
<af:outputText value="#{row.bindings.name.inputValue}"
styleClass="smallHeight" id="ac116"/>
</af:column>
<af:column width="6%" headerText="desc"
id="c253">
<af:outputText value="#{row.bindings.desc.inputValue}"
id="socV79"/>
</af:column>
<af:column width="6%"
headerText="startdate"
id="c254">
<af:inputDate value="#{row.bindings.startdate.inputValue}"
readOnly="true" id="id68">
<af:convertDateTime pattern="dd/MM/yyyy"
secondaryPattern="ddMMyyyy"/>
</af:inputDate>
</af:column>
<af:column width="5%"
headerText="sal"
id="c255">
<af:outputText value="#{row.bindings.sal.inputValue}"
id="soc85"/>
</af:column>
<af:column width="3%"
headerText="dept"
id="c256"
visible="#{(bindings.deptId.inputValue eq 'M' and bindings.listSize.inputValue == 0)}">
<af:outputText value="#{row.bindings.dept.inputValue}"
id="soc86"/>
</af:column>
<af:column width="4%"
headerText="age"
id="c257"
>
<af:outputText value="#{row.bindings.age.inputValue}"
id="soc87"/>
</af:column>
<af:column id="c278" width="1%"
>
<af:link icon="/images/basic/dark/search.png"
id="shPsbd"
shortDesc="search"
actionListener="#{viewScope.crud.onsearchActionListener}"
/>
</af:column>
<af:column sortProperty="#{bindings.employeeList.hints.exp.name}"
sortable="true" width="5%"
headerText="experienceYear" id="c260">
<af:outputText value="#{row.bindings.exp.inputValue}"
id="it118"/>
</af:column>
</af:table>
Regards

File Process in C

I wrote these codes for my project but I have error in these codes.
This function's purpose is to add new client in this file. When I process it, it's okay but if I want to see my clients from file I process search function it gets to me more than my clients like that. I tried to work it by using fscanf but when I tried it, my addition function isn't working completely because it is not read 'kisiler.iz' (means registration track).
Like that
void ekle(struct kisiyapi kisiler)
{
char secenek;
dosya=fopen("kisiler.txt","a+");
do
{
kisiler.iz=' ';
printf("Kisi no giriniz\n");
scanf("%d",&kisiler.kisino);
kaypos=(kisiler.kisino-1) * sizeof(kisiler);
fseek(dosya,kaypos,SEEK_SET);
fread(&kisiler,sizeof(kisiler),1,dosya);
if(kisiler.iz!='*')
{
printf("Kisinin adini giriniz\n");
scanf("%s",&kisiler.ad);
printf("Kisinin soyadini giriniz\n");
scanf("%s",&kisiler.soyad);
printf("Kisinin Ev Telefonunu giriniz\n");
scanf("%s",&kisiler.evtel);
printf("Kisinin Cep Telefonunu giriniz\n");
scanf("%s",&kisiler.ceptel);
printf("Kisinin Is Telefonunu giriniz\n");
scanf("%s",&kisiler.istel);
printf("Kisinin Dogum tarihini sirasiyla gun/ay/yil olarak giriniz\n");
scanf("%d",&kisiler.dogumgunu);
scanf("%d",&kisiler.dogumayi);
scanf("%d",&kisiler.dogumyili);
printf("Kisinin yasadigi Il girin\n");
scanf("%s",&kisiler.il);
printf("Kisinin yasadigi Ilce girin\n");
scanf("%s",&kisiler.ilce);
printf("Kisinin yasadigi mahalleyi girin\n");
scanf("%s",&kisiler.mahalle);
printf("Kisinin yasadigi sokak no girin\n");
scanf("%s",&kisiler.sokak);
kisiler.iz='*';
fseek(dosya,kaypos,SEEK_SET);
fwrite(&kisiler,sizeof(kisiler),1,dosya);
}
else
{
printf("Mevcut kayit var\n");
}
printf("\nTekrar ekleme yapmak istiyor musunuz ? [e veya h]");
secenek=getch();
}
while(secenek!='h');
fclose(dosya);
}
and these codes' purpose is update information of any client but it's not working because my feof loop isn't working or work forever.
Therefore, I can't update my informations.
void guncelle(struct kisiyapi kisiler)
{
char aranan[20];
int i=0;
dosya=fopen("kisiler.txt","r");
yeni=fopen("temp.txt","w");
if(dosya==NULL)
printf("Dosyaya ulasilamadi\n");
printf("Guncellemek istediginiz kisinin adini giriniz\n");
scanf("%s",aranan);
while(!feof(dosya))
{
i++;
}
/*
while(!feof(dosya))
{
fread(&kisiler,sizeof(kisiler),1,dosya);
kaypos=(kisiler.kisino-1) * sizeof(kisiler);
if(strcmp(aranan,kisiler.ad)==0)
{
printf("Kisinin adini giriniz\n");
scanf("%s",&kisiler.ad);
printf("Kisinin soyadini giriniz\n");
scanf("%s",&kisiler.soyad);
printf("Kisinin Ev Telefonunu giriniz\n");
scanf("%s",&kisiler.evtel);
printf("Kisinin Cep Telefonunu giriniz\n");
scanf("%s",&kisiler.ceptel);
printf("Kisinin Is Telefonunu giriniz\n");
scanf("%s",&kisiler.istel);
printf("Kisinin Dogum tarihini sirasiyla gun/ay/yil olarak giriniz\n");
scanf("%d",&kisiler.dogumgunu);
scanf("%d",&kisiler.dogumayi);
scanf("%d",&kisiler.dogumyili);
printf("Kisinin yasadigi Il girin\n");
scanf("%s",&kisiler.il);
printf("Kisinin yasadigi Ilce girin\n");
scanf("%s",&kisiler.ilce);
printf("Kisinin yasadigi mahalleyi girin\n");
scanf("%s",&kisiler.mahalle);
printf("Kisinin yasadigi sokak no girin\n");
scanf("%s",&kisiler.sokak);
kisiler.iz='*';
fseek(yeni,kaypos,SEEK_SET);
fprintf(dosya,"%s\t%s\t%s\t%s\t%s\t%d %d %d\t%s\t%s\t%s\t%s\t%c",kisiler.ad,kisiler.soyad,kisiler.evtel,kisiler.ceptel,kisiler.istel
,*kisiler.dogumgunu,*kisiler.dogumayi,*kisiler.dogumyili,kisiler.il,kisiler.ilce,kisiler.mahalle,kisiler.sokak,kisiler.iz);
}
else if(strcmp(aranan,kisiler.ad)!=0)
{
fseek(yeni,kaypos,SEEK_SET);
fseek(dosya,kaypos,SEEK_SET);
fwrite(&kisiler,sizeof(kisiler),1,yeni);
}
}
fclose(dosya);
fclose(yeni);
*/
}
If you understand my codes please help me I have no time to prepare it.
The "eof" flag is only set once you try to read from beyond the end of the file. Your loop doesn't read anything from the file so it will never reach the end and will continue forever.
And very much related, you should read Why is “while ( !feof (file) )” always wrong?.

Get certain properties from large json object

Im receiving a huge json object, I need to take only two properties from it.
The json comes like this
"{\r\n\"d\" : [\r\n{\r\n\"__metadata\": {\r\n\"uri\": \"http:\/\/xx.xx.xx\/AciApi.svc\/Port_Domestic(1191)\", \"type\": \"ACIModel.Port_Domestic\"\r\n}, \"PortID\": 1191, \"PortName\": \"PORTLAND\"\r\n}, {\r\n\"__metadata\": {\r\n\"uri\": \"http:\/\/xx.xx.xx\/AciApi.svc\/Port_Domestic(1192)\", \"type\": \"ACIModel.Port_Domestic\"\r\n}, \"PortID\": 1192, \"PortName\": \"BANGOR\"\r\n}, {\r\n\"__metadata\": {\r\n\"uri\": \"http:\/\/xx.xx.xx\/AciApi.svc\/Port_Domestic(1193)\", \"type\": \"ACIModel.Port_Domestic\"\r\n}, \"PortID\": 1193, \"PortName\": \"LUBEC\"\r\n}, {\r\n\"__metadata\": {\r\n\"uri\":....
I need only the PortName and the PortID to be like this
0:{portCode:"",portName:""},
1:{portCode:"",portName:""},
...
var jsonString = "{\r\n\"d\" : [\r\n{\r\n\"__metadata\": {\r\n\"uri\": \"http:\/\/xx.xx.xx\/AciApi.svc\/Port_Domestic(1191)\", \"type\": \"ACIModel.Port_Domestic\"\r\n}, \"PortID\": 1191, \"PortName\": \"PORTLAND\"\r\n}, {\r\n\"__metadata\": {\r\n\"uri\": \"http:\/\/xx.xx.xx\/AciApi.svc\/Port_Domestic(1192)\", \"type\": \"ACIModel.Port_Domestic\"\r\n}, \"PortID\": 1192, \"PortName\": \"BANGOR\"\r\n}, {\r\n\"__metadata\": {\r\n\"uri\": \"http:\/\/xx.xx.xx\/AciApi.svc\/Port_Domestic(1193)\", \"type\": \"ACIModel.Port_Domestic\"\r\n}, \"PortID\": 1193, \"PortName\": \"LUBEC\"\r\n}]}"
var jsonArray = JSON.parse(jsonString).d;
var arrayOfObjectsWithOnlyThose2Properties = jsonArray.map(function(item){
return {
"portCode": item.PortCode,
"portName": item.PortName
}
});
console.log(arrayOfObjectsWithOnlyThose2Properties);

Swift: How to swap two axes of a four-dimensional array?

To feed the data to a function correctly, I need to swap two axes in a four-dimensional array in Swift. I'd like to know how to implement or are there any useful function for this purpose.
In Python, if I use numpy.swapaxes(a, axis1, axis2), it's straightforward (https://docs.scipy.org/doc/numpy/reference/generated/numpy.swapaxes.html):
def swapaxes_from_tail_to_head(nparray):
nparray = np.swapaxes(nparray, 2, 3)
nparray = np.swapaxes(nparray, 1, 2)
nparray = np.swapaxes(nparray, 0, 1)
return nparray
Just note that if the array is two-dimensional, I can do like this:
func prettyPrintMatrix( _ matrix:[[Int]] ) {
for array in matrix {
print( array )
}
}
func main() -> (){
print( "MatrixTranspose_Demo" )
print()
let matrix =
[
[ 1, 2, 3 ],
[ 4, 5, 6 ],
]
print( "Matrix:")
prettyPrintMatrix( matrix )
print()
let transpose = transposeMatrix( matrix )
print( "Transpose matrix:")
prettyPrintMatrix( transpose )
print()
}
func transposeMatrix( _ matrix:[[Int]] ) -> [[Int]] {
var result = [[Int]](
repeating: [Int]( repeating: 0, count: matrix.count ),
count: matrix[ 0 ].count
)
for i in 0 ..< matrix.count {
for k in 0 ..< matrix[ 0 ].count {
result[ k ][ i ] = matrix[ i ][ k ]
}
}
return result
}
main()
// Reference: http://www.runswiftlang.com/
If you have any ideas how to do swapaxes for four-dimentional (or more) array, please let me know. I appreciate your help.
The simplest way is to hard code everything like the followings:
internal func swapaxesOfFlatArray4d<T>(originalArray: [T], axis1: Int, axis2: Int, dimensionOfArray: [Int]) -> [T] {
assert(axis1 != axis2)
assert(dimensionOfArray.count == 4)
assert(axis1 < dimensionOfArray.count)
assert(axis2 < dimensionOfArray.count)
assert(originalArray.count == dimensionOfArray.reduce(1, *))
assert((T.self == Float.self) || (T.self == Double.self))
var newArray = Array<T>()
if ((axis1 == 0 && axis2 == 1) || (axis1 == 1 && axis2 == 0)) {
for j in 0..<dimensionOfArray[1] {
for i in 0..<dimensionOfArray[0] {
for k in 0..<dimensionOfArray[2] {
for l in 0..<dimensionOfArray[3] {
newArray.append(originalArray[i*dimensionOfArray[1]*dimensionOfArray[2]*dimensionOfArray[3] + j*dimensionOfArray[2]*dimensionOfArray[3] + k*dimensionOfArray[3] + l])
}
}
}
}
} else if ((axis1 == 0 && axis2 == 2) || (axis1 == 2 && axis2 == 0)) {
for k in 0..<dimensionOfArray[2] {
for j in 0..<dimensionOfArray[1] {
for i in 0..<dimensionOfArray[0] {
for l in 0..<dimensionOfArray[3] {
newArray.append(originalArray[i*dimensionOfArray[1]*dimensionOfArray[2]*dimensionOfArray[3] + j*dimensionOfArray[2]*dimensionOfArray[3] + k*dimensionOfArray[3] + l])
}
}
}
}
} else if ((axis1 == 0 && axis2 == 3) || (axis1 == 3 && axis2 == 0)) {
for l in 0..<dimensionOfArray[3] {
for j in 0..<dimensionOfArray[1] {
for k in 0..<dimensionOfArray[2] {
for i in 0..<dimensionOfArray[0] {
newArray.append(originalArray[i*dimensionOfArray[1]*dimensionOfArray[2]*dimensionOfArray[3] + j*dimensionOfArray[2]*dimensionOfArray[3] + k*dimensionOfArray[3] + l])
}
}
}
}
} else if ((axis1 == 1 && axis2 == 2) || (axis1 == 2 && axis2 == 1)) {
for i in 0..<dimensionOfArray[0] {
for k in 0..<dimensionOfArray[2] {
for j in 0..<dimensionOfArray[1] {
for l in 0..<dimensionOfArray[3] {
newArray.append(originalArray[i*dimensionOfArray[1]*dimensionOfArray[2]*dimensionOfArray[3] + j*dimensionOfArray[2]*dimensionOfArray[3] + k*dimensionOfArray[3] + l])
}
}
}
}
} else if ((axis1 == 1 && axis2 == 3) || (axis1 == 3 && axis2 == 1)) {
for i in 0..<dimensionOfArray[0] {
for l in 0..<dimensionOfArray[3] {
for k in 0..<dimensionOfArray[2] {
for j in 0..<dimensionOfArray[1] {
newArray.append(originalArray[i*dimensionOfArray[1]*dimensionOfArray[2]*dimensionOfArray[3] + j*dimensionOfArray[2]*dimensionOfArray[3] + k*dimensionOfArray[3] + l])
}
}
}
}
} else if ((axis1 == 2 && axis2 == 3) || (axis1 == 3 && axis2 == 2)) {
for i in 0..<dimensionOfArray[0] {
for j in 0..<dimensionOfArray[1] {
for l in 0..<dimensionOfArray[3] {
for k in 0..<dimensionOfArray[2] {
newArray.append(originalArray[i*dimensionOfArray[1]*dimensionOfArray[2]*dimensionOfArray[3] + j*dimensionOfArray[2]*dimensionOfArray[3] + k*dimensionOfArray[3] + l])
}
}
}
}
} else {
fatalError("Didn't match all the case")
}
return newArray
}
To decrease the amount of the code, you can a class to change the order of for loops.
Change order of for loops?
It is fairly easy to make a transpose function for a 2d matrix:
func transpose<T>(_ matrix:[[T]]) -> [[T]]
{
return matrix.reduce([[T]]())
{
zip($0,$1).map{$0+[$1]}
+ $0.dropFirst($1.count)
+ $1.dropFirst($0.count).map{[$0]}
}
}
Once you have that, all other transpositions of any dimensions can be converted to a series of 2d transposes on consecutive dimensions (essentially swapping them)
let array12 = (1...4).map{ n in (1...4).map{n*10 + $0} }
let array123 = (1...4).map{ n in array12.map{ $0.map{ n*100 + $0 } } }
let array1234 = (1...4).map{ n in array123.map{ $0.map{ $0.map{ n*1000 + $0 } } } }
let array2134 = transpose(array1234) // swap dimensions 1 and 2
let array1324 = array1234.map{transpose($0)} // swap dimensions 2 and 3
let array1243 = array1234.map{$0.map{transpose($0)}} // swap dimensions 3 and 4
Reusing these 3 basic dimension swaps, all other combinations of the 4 dimensions are possible.
let array2143 = array2134.map{$0.map{transpose($0)}}
let array2413 = array2143.map{transpose($0)}
let array4213 = transpose(array2413)
let array4231 = array4213.map{$0.map{transpose($0)}}
let array4321 = array4231.map{transpose($0)}
// and so on ...
To help test this, I made a 4d print function for the matrix that I used in the playground:
It prints in row column order so you get dimension one as a vertical group of "blocks", dimension 2 as a column of blocks, dimension 3 is rows of each block and dimension 4 is the columns of each block:
func print4d<T>(_ matrix4d:[[[[T]]]])
{
var lines:[String] = []
for d1 in matrix4d
{
lines = []
for (indent,d2) in d1.enumerated()
{
let indentWidth = indent * 80
var lineNumber = 0
let blankLine = "".padding(toLength:indentWidth, withPad:" ", startingAt:0)
for d34 in d2
{
while lines.count <= lineNumber
{ lines.append(blankLine) }
lines[lineNumber] = lines[lineNumber]
.padding(toLength:indentWidth, withPad:" ", startingAt:0)
+ " \(d34)"
lineNumber += 1
}
for index in lines.indices
{
while lines[index].contains(" ")
{ lines[index] = lines[index].replacingOccurrences(of: " ", with: " ") }
}
}
lines.forEach{ print($0) }
print("")
}
}
4d matrix : d1, d2, d3, d4
===========================
[1111, 1112, 1113, 1114] [1211, 1212, 1213, 1214] [1311, 1312, 1313, 1314] [1411, 1412, 1413, 1414]
[1121, 1122, 1123, 1124] [1221, 1222, 1223, 1224] [1321, 1322, 1323, 1324] [1421, 1422, 1423, 1424]
[1131, 1132, 1133, 1134] [1231, 1232, 1233, 1234] [1331, 1332, 1333, 1334] [1431, 1432, 1433, 1434]
[1141, 1142, 1143, 1144] [1241, 1242, 1243, 1244] [1341, 1342, 1343, 1344] [1441, 1442, 1443, 1444]
[2111, 2112, 2113, 2114] [2211, 2212, 2213, 2214] [2311, 2312, 2313, 2314] [2411, 2412, 2413, 2414]
[2121, 2122, 2123, 2124] [2221, 2222, 2223, 2224] [2321, 2322, 2323, 2324] [2421, 2422, 2423, 2424]
[2131, 2132, 2133, 2134] [2231, 2232, 2233, 2234] [2331, 2332, 2333, 2334] [2431, 2432, 2433, 2434]
[2141, 2142, 2143, 2144] [2241, 2242, 2243, 2244] [2341, 2342, 2343, 2344] [2441, 2442, 2443, 2444]
[3111, 3112, 3113, 3114] [3211, 3212, 3213, 3214] [3311, 3312, 3313, 3314] [3411, 3412, 3413, 3414]
[3121, 3122, 3123, 3124] [3221, 3222, 3223, 3224] [3321, 3322, 3323, 3324] [3421, 3422, 3423, 3424]
[3131, 3132, 3133, 3134] [3231, 3232, 3233, 3234] [3331, 3332, 3333, 3334] [3431, 3432, 3433, 3434]
[3141, 3142, 3143, 3144] [3241, 3242, 3243, 3244] [3341, 3342, 3343, 3344] [3441, 3442, 3443, 3444]
[4111, 4112, 4113, 4114] [4211, 4212, 4213, 4214] [4311, 4312, 4313, 4314] [4411, 4412, 4413, 4414]
[4121, 4122, 4123, 4124] [4221, 4222, 4223, 4224] [4321, 4322, 4323, 4324] [4421, 4422, 4423, 4424]
[4131, 4132, 4133, 4134] [4231, 4232, 4233, 4234] [4331, 4332, 4333, 4334] [4431, 4432, 4433, 4434]
[4141, 4142, 4143, 4144] [4241, 4242, 4243, 4244] [4341, 4342, 4343, 4344] [4441, 4442, 4443, 4444]
4d matrix : d2, d1, d3, d4
===========================
[1111, 1112, 1113, 1114] [2111, 2112, 2113, 2114] [3111, 3112, 3113, 3114] [4111, 4112, 4113, 4114]
[1121, 1122, 1123, 1124] [2121, 2122, 2123, 2124] [3121, 3122, 3123, 3124] [4121, 4122, 4123, 4124]
[1131, 1132, 1133, 1134] [2131, 2132, 2133, 2134] [3131, 3132, 3133, 3134] [4131, 4132, 4133, 4134]
[1141, 1142, 1143, 1144] [2141, 2142, 2143, 2144] [3141, 3142, 3143, 3144] [4141, 4142, 4143, 4144]
[1211, 1212, 1213, 1214] [2211, 2212, 2213, 2214] [3211, 3212, 3213, 3214] [4211, 4212, 4213, 4214]
[1221, 1222, 1223, 1224] [2221, 2222, 2223, 2224] [3221, 3222, 3223, 3224] [4221, 4222, 4223, 4224]
[1231, 1232, 1233, 1234] [2231, 2232, 2233, 2234] [3231, 3232, 3233, 3234] [4231, 4232, 4233, 4234]
[1241, 1242, 1243, 1244] [2241, 2242, 2243, 2244] [3241, 3242, 3243, 3244] [4241, 4242, 4243, 4244]
[1311, 1312, 1313, 1314] [2311, 2312, 2313, 2314] [3311, 3312, 3313, 3314] [4311, 4312, 4313, 4314]
[1321, 1322, 1323, 1324] [2321, 2322, 2323, 2324] [3321, 3322, 3323, 3324] [4321, 4322, 4323, 4324]
[1331, 1332, 1333, 1334] [2331, 2332, 2333, 2334] [3331, 3332, 3333, 3334] [4331, 4332, 4333, 4334]
[1341, 1342, 1343, 1344] [2341, 2342, 2343, 2344] [3341, 3342, 3343, 3344] [4341, 4342, 4343, 4344]
[1411, 1412, 1413, 1414] [2411, 2412, 2413, 2414] [3411, 3412, 3413, 3414] [4411, 4412, 4413, 4414]
[1421, 1422, 1423, 1424] [2421, 2422, 2423, 2424] [3421, 3422, 3423, 3424] [4421, 4422, 4423, 4424]
[1431, 1432, 1433, 1434] [2431, 2432, 2433, 2434] [3431, 3432, 3433, 3434] [4431, 4432, 4433, 4434]
[1441, 1442, 1443, 1444] [2441, 2442, 2443, 2444] [3441, 3442, 3443, 3444] [4441, 4442, 4443, 4444]
4d matrix : d1, d2, d4, d3
===========================
[1111, 1121, 1131, 1141] [2111, 2121, 2131, 2141] [3111, 3121, 3131, 3141] [4111, 4121, 4131, 4141]
[1112, 1122, 1132, 1142] [2112, 2122, 2132, 2142] [3112, 3122, 3132, 3142] [4112, 4122, 4132, 4142]
[1113, 1123, 1133, 1143] [2113, 2123, 2133, 2143] [3113, 3123, 3133, 3143] [4113, 4123, 4133, 4143]
[1114, 1124, 1134, 1144] [2114, 2124, 2134, 2144] [3114, 3124, 3134, 3144] [4114, 4124, 4134, 4144]
[1211, 1221, 1231, 1241] [2211, 2221, 2231, 2241] [3211, 3221, 3231, 3241] [4211, 4221, 4231, 4241]
[1212, 1222, 1232, 1242] [2212, 2222, 2232, 2242] [3212, 3222, 3232, 3242] [4212, 4222, 4232, 4242]
[1213, 1223, 1233, 1243] [2213, 2223, 2233, 2243] [3213, 3223, 3233, 3243] [4213, 4223, 4233, 4243]
[1214, 1224, 1234, 1244] [2214, 2224, 2234, 2244] [3214, 3224, 3234, 3244] [4214, 4224, 4234, 4244]
[1311, 1321, 1331, 1341] [2311, 2321, 2331, 2341] [3311, 3321, 3331, 3341] [4311, 4321, 4331, 4341]
[1312, 1322, 1332, 1342] [2312, 2322, 2332, 2342] [3312, 3322, 3332, 3342] [4312, 4322, 4332, 4342]
[1313, 1323, 1333, 1343] [2313, 2323, 2333, 2343] [3313, 3323, 3333, 3343] [4313, 4323, 4333, 4343]
[1314, 1324, 1334, 1344] [2314, 2324, 2334, 2344] [3314, 3324, 3334, 3344] [4314, 4324, 4334, 4344]
[1411, 1421, 1431, 1441] [2411, 2421, 2431, 2441] [3411, 3421, 3431, 3441] [4411, 4421, 4431, 4441]
[1412, 1422, 1432, 1442] [2412, 2422, 2432, 2442] [3412, 3422, 3432, 3442] [4412, 4422, 4432, 4442]
[1413, 1423, 1433, 1443] [2413, 2423, 2433, 2443] [3413, 3423, 3433, 3443] [4413, 4423, 4433, 4443]
[1414, 1424, 1434, 1444] [2414, 2424, 2434, 2444] [3414, 3424, 3434, 3444] [4414, 4424, 4434, 4444]
4d matrix : d1, d3, d2, d4
===========================
[1111, 1112, 1113, 1114] [1121, 1122, 1123, 1124] [1131, 1132, 1133, 1134] [1141, 1142, 1143, 1144]
[2111, 2112, 2113, 2114] [2121, 2122, 2123, 2124] [2131, 2132, 2133, 2134] [2141, 2142, 2143, 2144]
[3111, 3112, 3113, 3114] [3121, 3122, 3123, 3124] [3131, 3132, 3133, 3134] [3141, 3142, 3143, 3144]
[4111, 4112, 4113, 4114] [4121, 4122, 4123, 4124] [4131, 4132, 4133, 4134] [4141, 4142, 4143, 4144]
[1211, 1212, 1213, 1214] [1221, 1222, 1223, 1224] [1231, 1232, 1233, 1234] [1241, 1242, 1243, 1244]
[2211, 2212, 2213, 2214] [2221, 2222, 2223, 2224] [2231, 2232, 2233, 2234] [2241, 2242, 2243, 2244]
[3211, 3212, 3213, 3214] [3221, 3222, 3223, 3224] [3231, 3232, 3233, 3234] [3241, 3242, 3243, 3244]
[4211, 4212, 4213, 4214] [4221, 4222, 4223, 4224] [4231, 4232, 4233, 4234] [4241, 4242, 4243, 4244]
[1311, 1312, 1313, 1314] [1321, 1322, 1323, 1324] [1331, 1332, 1333, 1334] [1341, 1342, 1343, 1344]
[2311, 2312, 2313, 2314] [2321, 2322, 2323, 2324] [2331, 2332, 2333, 2334] [2341, 2342, 2343, 2344]
[3311, 3312, 3313, 3314] [3321, 3322, 3323, 3324] [3331, 3332, 3333, 3334] [3341, 3342, 3343, 3344]
[4311, 4312, 4313, 4314] [4321, 4322, 4323, 4324] [4331, 4332, 4333, 4334] [4341, 4342, 4343, 4344]
[1411, 1412, 1413, 1414] [1421, 1422, 1423, 1424] [1431, 1432, 1433, 1434] [1441, 1442, 1443, 1444]
[2411, 2412, 2413, 2414] [2421, 2422, 2423, 2424] [2431, 2432, 2433, 2434] [2441, 2442, 2443, 2444]
[3411, 3412, 3413, 3414] [3421, 3422, 3423, 3424] [3431, 3432, 3433, 3434] [3441, 3442, 3443, 3444]
[4411, 4412, 4413, 4414] [4421, 4422, 4423, 4424] [4431, 4432, 4433, 4434] [4441, 4442, 4443, 4444]
4d matrix : d4, d2, d3, d1
===========================
[1111, 2111, 3111, 4111] [1211, 2211, 3211, 4211] [1311, 2311, 3311, 4311] [1411, 2411, 3411, 4411]
[1121, 2121, 3121, 4121] [1221, 2221, 3221, 4221] [1321, 2321, 3321, 4321] [1421, 2421, 3421, 4421]
[1131, 2131, 3131, 4131] [1231, 2231, 3231, 4231] [1331, 2331, 3331, 4331] [1431, 2431, 3431, 4431]
[1141, 2141, 3141, 4141] [1241, 2241, 3241, 4241] [1341, 2341, 3341, 4341] [1441, 2441, 3441, 4441]
[1112, 2112, 3112, 4112] [1212, 2212, 3212, 4212] [1312, 2312, 3312, 4312] [1412, 2412, 3412, 4412]
[1122, 2122, 3122, 4122] [1222, 2222, 3222, 4222] [1322, 2322, 3322, 4322] [1422, 2422, 3422, 4422]
[1132, 2132, 3132, 4132] [1232, 2232, 3232, 4232] [1332, 2332, 3332, 4332] [1432, 2432, 3432, 4432]
[1142, 2142, 3142, 4142] [1242, 2242, 3242, 4242] [1342, 2342, 3342, 4342] [1442, 2442, 3442, 4442]
[1113, 2113, 3113, 4113] [1213, 2213, 3213, 4213] [1313, 2313, 3313, 4313] [1413, 2413, 3413, 4413]
[1123, 2123, 3123, 4123] [1223, 2223, 3223, 4223] [1323, 2323, 3323, 4323] [1423, 2423, 3423, 4423]
[1133, 2133, 3133, 4133] [1233, 2233, 3233, 4233] [1333, 2333, 3333, 4333] [1433, 2433, 3433, 4433]
[1143, 2143, 3143, 4143] [1243, 2243, 3243, 4243] [1343, 2343, 3343, 4343] [1443, 2443, 3443, 4443]
[1114, 2114, 3114, 4114] [1214, 2214, 3214, 4214] [1314, 2314, 3314, 4314] [1414, 2414, 3414, 4414]
[1124, 2124, 3124, 4124] [1224, 2224, 3224, 4224] [1324, 2324, 3324, 4324] [1424, 2424, 3424, 4424]
[1134, 2134, 3134, 4134] [1234, 2234, 3234, 4234] [1334, 2334, 3334, 4334] [1434, 2434, 3434, 4434]
[1144, 2144, 3144, 4144] [1244, 2244, 3244, 4244] [1344, 2344, 3344, 4344] [1444, 2444, 3444, 4444]
The lack of direct support for matrix operations in Swift was bothering me so I played around with array extensions and cam up with a few methods that could probably make thing a bit easier.
extension Array
{
func asMatrix(_ axisSizes: Int ...) -> [Any] { return asMatrix(axisSizes) }
func asMatrix(_ axisSizes:[Int]) -> [Any]
{
if count == 0 { return [] }
let requiredVectorSize = axisSizes.reduce(1,*)
let flatData = asVector
var newArray:[Any] = flatData
while newArray.count < requiredVectorSize { newArray = newArray + flatData }
for axisSize in axisSizes.dropFirst().reversed()
{
newArray = (0..<newArray.count/axisSize)
.map{($0*axisSize,($0+1)*axisSize)}
.map{newArray[$0..<$1].map{$0}}
}
return newArray
}
var matrixSize:[Int]
{
get { return [count] + ((first as? [Any])?.matrixSize ?? []) }
set { self = asVector.asMatrix(newValue) as! [Element] }
}
func vectorIndex(of indexes:[Int]) -> Int
{
return zip(matrixSize,indexes).reduce(0){ $0 * $1.0 + $1.1 }
}
func matrixIndex(of vectorIndex:Int) -> [Int]
{
var result:[Int] = []
var vectorIndex = vectorIndex
for dim in matrixSize.reversed()
{
result.append(vectorIndex % dim)
vectorIndex = vectorIndex / dim
}
return result.reversed()
}
func enumeratedMatrix() -> [([Int],Any)]
{
return asVector.enumerated().map{(self.matrixIndex(of:$0),$1)}
}
var vectorSize:Int { return matrixSize.reduce(1,*) }
var asVector:[Any]
{
get { return (self as? [[Any]])?.reduce(Array<Any>()){$0+$1}.asVector ?? self}
set { self = newValue.asMatrix(matrixSize) as! [Element] }
}
subscript(indexes:[Int]) -> Any
{
get { return indexes.reduce(self as Any){ ($0 as! [Any])[$1] } }
set {
if indexes.count == 1
{
self[indexes.first!] = newValue as! Element
}
else
{
var subArray = self[indexes.first!] as! Array<Any>
let subIndexes:[Int] = indexes.dropFirst().map{$0}
subArray[subIndexes] = newValue
self[indexes.first!] = subArray as! Element
}
}
}
func transposedMatrix(_ dim1:Int=0, _ dim2:Int=1) -> [Any]
{
if dim1 == dim2 { return self }
var transposedSizes = matrixSize
swap(&transposedSizes[dim1],&transposedSizes[dim2])
var indexMap = (0..<transposedSizes.count).map{$0}
swap(&indexMap[dim1],&indexMap[dim2])
let mapping = (0..<vectorSize)
.map{($0, matrixIndex(of:$0))}
.map{(vi,mi) in (vi,indexMap.map{mi[$0]})}
.map{(vi,mi) in (vi,self.vectorIndex(of:mi)) }
var flatData = asVector
return mapping
.sorted{$0.1 < $1.1}
.map{flatData[$0.0]}
.asMatrix(transposedSizes)
}
}
The only issue remaining is that I had to use type erasure so these matrices are treated as arrays or Any and require some type casting for actual use. Nevertheless, it is easier to manipulate them:
// initialized from vectors:
//
let squareNumbers = (0..<64).map{$0}
var chessBoard = squareNumbers.asMatrix(8,8)
// swapping axes
//
let m4Dim4842 = [0].asMatrix(4,8,4,2) // 1 element vector is repeated to fill content
let m4Dim2844 = m4Dim4842.transposedMatrix(3,0) // swapped dimensions 0 and 3
// double brackets to access elements
//
let queenPos = chessBoard[[4,0]] as! Int
chessBoard[[4,0]] = queenPos
// enumeration to traverse all elements
// (and data assignment using a 1d vector)
chessBoard.asVector = chessBoard.enumeratedMatrix().map{$0.0[0]==$0.0[1] ? 1 : 0}

Group by does not work - SQL 2008 R2

I have 3 rows that I need to be outputted into just 1 row, the script below should do, but I can't seem to have the expected result, it always shows up as 3 rows, is there something I'm missing? should I sum all the fields since they are all in the "GROUP" clause?
Btw, its working just before I made changes to the following result fields;
TSL_DAY_A
TSL_NET_A
TSL_TX_SAL
TSL_CHG
These fields were initially assigned with 0.00 as default values.
I have my eyes already tired staring at it,...
SELECT BR_CODE
,N_CHECK
,CLAS_C
,CLAS_TRD_C
,STOR_NO
,SUM(TSL_NEW_A) AS TSL_NEW_A
,SUM(TSL_OLD_A) AS TSL_OLD_A
,SalesType
,SUM(TSL_DAY_A) AS TSL_DAY_A
,SUM(TSL_DIS_A) AS TSL_DIS_A
,TSL_DIS_B
,SUM(TSL_DIS_C) AS TSL_DIS_C
,TSL_DIS_D
,SUM(TSL_DIS_E) AS TSL_DIS_E
,TSL_Dis_F
,TSL_Dis_G
,TSL_Dis_H
,TSL_Dis_I
,TSL_Dis_J
,TSL_Dis_K
,TSL_Dis_L
,SUM(TSL_TAX_A) AS TSL_TAX_A
,TSL_TAX_B
,TSL_ADJ_A
,TSL_ADJ_POS
,TS_ADJ_NEG
,TSL_ADJ_NT_POS
,TSL_ADJ_NT_NEG
,SUM(TSL_NET_A) AS TSL_NET_A
,SUM(TSL_VOID) AS TSL_VOID
,SUM(TSL_RFND) AS TSL_RFND
,SUM(TSL_TX_SAL) AS TSL_TX_SAL
,SUM(TSL_NX_SAL) AS TSL_NX_SAL
,TSL_CHG
,SUM(TSL_CSH) AS TSL_CSH
,SUM(TSL_GC) AS TSL_GC
,TSL_EPS
,TSL_TND
,TSL_MCRD
,TSL_VISA
,TSL_AMEX
,TSL_DINERS
,TSL_JBC
,TSL_OTCRD
,TSL_SV_CHG
,TSL_OT_CHG
,SUM(TSL_FT) AS TSL_FT
,SUM(TSL_LT) AS TSL_LT
,SUM(TSL_NT) AS TSL_NT
,SUM(TSL_BEG_INV) AS TSL_BEG_INV
,SUM(TSL_END_INV) AS TSL_END_INV
,SUM(TSL_TC_CASH) AS TSL_TC_CASH
,SUM(TSL_TC_GC) AS TSL_TC_GC
,TSL_TC_EPS
,TSL_TC_TND
,TSL_TC_MCD
,TSL_TC_VIS
,TSL_TC_AMX
,TSL_TC_DIN
,TSL_TC_JBC
,TSL_TC_OC
,TSL_MCH
,TSL_SRL
,SUM(TSL_ZCNT) AS TSL_ZCNT
,TSL_TIME
,TSL_DTE
FROM(
SELECT
BR_CODE
,N_CHECK
,CLAS_C
,CLAS_TRD_C
,STOR_NO
,SUM(TSL_NEW_A) AS TSL_NEW_A
,SUM(TSL_OLD_A) AS TSL_OLD_A
,SalesType
,SUM(TSL_DAY_A) AS TSL_DAY_A
,SUM(TSL_DIS_A) AS TSL_DIS_A
,TSL_DIS_B
,SUM(TSL_DIS_C) AS TSL_DIS_C
,TSL_DIS_D
,SUM(TSL_DIS_E) AS TSL_DIS_E
,TSL_Dis_F
,TSL_Dis_G
,TSL_Dis_H
,TSL_Dis_I
,TSL_Dis_J
,TSL_Dis_K
,TSL_Dis_L
,SUM(TSL_TAX_A) AS TSL_TAX_A
,TSL_TAX_B
,TSL_ADJ_A
,TSL_ADJ_POS
,TS_ADJ_NEG
,TSL_ADJ_NT_POS
,TSL_ADJ_NT_NEG
,SUM(TSL_NET_A) AS TSL_NET_A
,SUM(TSL_VOID) AS TSL_VOID
,SUM(TSL_RFND) AS TSL_RFND
,SUM(TSL_TX_SAL) AS TSL_TX_SAL
,SUM(TSL_NX_SAL) AS TSL_NX_SAL
,TSL_CHG
,SUM(TSL_CSH) AS TSL_CSH
,SUM(TSL_GC) AS TSL_GC
,TSL_EPS
,TSL_TND
,TSL_MCRD
,TSL_VISA
,TSL_AMEX
,TSL_DINERS
,TSL_JBC
,TSL_OTCRD
,TSL_SV_CHG
,TSL_OT_CHG
,SUM(TSL_FT) AS TSL_FT
,SUM(TSL_LT) AS TSL_LT
,SUM(TSL_NT) AS TSL_NT
,SUM(TSL_BEG_INV) AS TSL_BEG_INV
,SUM(TSL_END_INV) AS TSL_END_INV
,SUM(TSL_TC_CASH) AS TSL_TC_CASH
,SUM(TSL_TC_GC) AS TSL_TC_GC
,TSL_TC_EPS
,TSL_TC_TND
,TSL_TC_MCD
,TSL_TC_VIS
,TSL_TC_AMX
,TSL_TC_DIN
,TSL_TC_JBC
,TSL_TC_OC
,TSL_MCH
,TSL_SRL
,SUM(TSL_ZCNT) AS TSL_ZCNT
,TSL_TIME
,TSL_DTE
FROM
(SELECT
#branchcode AS BR_CODE
,#ncheck AS N_CHECK
,#classc AS CLAS_C
,#classtrd AS CLAS_TRD_C
,#storeno AS STOR_NO
,SUM(CAST(NGTOTAL AS DECIMAL(16,2)) + CAST(OGTOTAL AS DECIMAL(16,2))) AS TSL_NEW_A
,SUM(CAST(OGTOTAL AS DECIMAL(16,2))) AS TSL_OLD_A
,#salestype AS SalesType
,SUM(((CAST(SALESREGULAR AS DECIMAL(16,2)) - CAST(SALESVATEXEMPT AS DECIMAL(16,2))) +
CAST(SALESCD20 AS DECIMAL(16,2)) +
CAST(SALESCD5 AS DECIMAL(16,2)) +
CAST(SALEPWD AS DECIMAL(16,2)) +
CAST(SALESTGOVT AS DECIMAL(16,2)) +
CAST(SALESZERORATED AS DECIMAL(16,2)) +
CAST(DISCREGULARAMT AS DECIMAL(16,2)) +
CAST(DISCSCD20AMT AS DECIMAL(16,2)) +
CAST(DISCSCD5AMT AS DECIMAL(16,2)) +
CAST(DISCPWD20AMT AS DECIMAL(16,2)) +
CAST(DISCPWD5AMT AS DECIMAL(16,2)) +
CAST(VOIDTRANAMT AS DECIMAL(16,2)) +
CAST(ITEMVOIDAMT AS DECIMAL(16,2)) +
CAST(TICKETRETAMT AS DECIMAL(16,2)) +
CAST(ITEMRETAMT AS DECIMAL(16,2)))/1.12) + CAST(SALESVATEXEMPT AS DECIMAL(16,2)) AS TSL_DAY_A --SUM(cast(round((cast(TSALES as decimal)/1.12),2) AS DECIMAL(16,2))) AS TSL_DAY_A --Help
,SUM(ABS(CAST(DISCREGULARAMT AS DECIMAL(16,2)))) AS TSL_DIS_A
,0.00 AS TSL_DIS_B
,SUM(CAST(DISCSCD20AMT AS DECIMAL(16,2)) + CAST(DISCSCD5AMT AS DECIMAL(16,2))) AS TSL_DIS_C
,0.00 AS TSL_DIS_D
,SUM(CAST(DISCSCD20AMT AS DECIMAL(16,2)) + CAST(DISCSCD5AMT AS DECIMAL(16,2))) AS TSL_DIS_E
,0.00 AS TSL_Dis_F
,0.00 AS TSL_Dis_G
,0.00 AS TSL_Dis_H
,0.00 AS TSL_Dis_I
,0.00 AS TSL_Dis_J
,0.00 AS TSL_Dis_K
,0.00 AS TSL_Dis_L
,SUM(CAST(VATSALEAMT AS DECIMAL(16,2))) AS TSL_TAX_A
,0.00 AS TSL_TAX_B
,0.00 TSL_ADJ_A
,0.00 AS TSL_ADJ_POS
,0.00 AS TS_ADJ_NEG
,0.00 AS TSL_ADJ_NT_POS
,0.00 AS TSL_ADJ_NT_NEG
,SUM(CAST(DGROSSSALES AS DECIMAL(16,2)) - CAST(TOTALTAXVALUE AS DECIMAL(16,2))) AS TSL_NET_A --Help
,SUM(CAST(VOIDTRANAMT AS DECIMAL(16,2))) AS TSL_VOID
,SUM(ABS(CAST(ITEMRETAMT AS DECIMAL(16,2)))) AS TSL_RFND
,SUM(((CAST(SALESREGULAR AS DECIMAL(16,2)) + CAST(SALESVATEXEMPT AS DECIMAL(16,2))) +
CAST(SALESCD20 AS DECIMAL(16,2)) +
CAST(SALESCD5 AS DECIMAL(16,2)) +
CAST(SALEPWD AS DECIMAL(16,2)) +
CAST(SALESTGOVT AS DECIMAL(16,2)) +
CAST(SALESZERORATED AS DECIMAL(16,2)) +
CAST(DISCREGULARAMT AS DECIMAL(16,2)) +
CAST(DISCSCD20AMT AS DECIMAL(16,2)) +
CAST(DISCSCD5AMT AS DECIMAL(16,2)) +
CAST(DISCPWD20AMT AS DECIMAL(16,2)) +
CAST(DISCPWD5AMT AS DECIMAL(16,2)) +
CAST(VOIDTRANAMT AS DECIMAL(16,2)) +
CAST(ITEMVOIDAMT AS DECIMAL(16,2)) +
CAST(TICKETRETAMT AS DECIMAL(16,2)) +
CAST(ITEMRETAMT AS DECIMAL(16,2)))) AS TSL_TX_SAL --Help
,(CAST(SALESVATEXEMPT AS DECIMAL(16,2)) + (CAST(ZERORATEDSALEAMT AS DECIMAL(16,2)) - CAST(ZERORATEDSALETAXVALUE AS DECIMAL(16,2)))) AS TSL_NX_SAL
,SUM(CAST(CCARDATMCHRGONLINEAMT AS DECIMAL(16,2))) AS TSL_CHG --Help
,SUM(CAST(TENDERCASHAMT AS DECIMAL(16,2))) AS TSL_CSH
,SUM(CAST(OTHTENDERSMGCAMT AS DECIMAL(16,2)) + CAST(OTHTENDERSODEXOAMT AS DECIMAL(16,2))) AS TSL_GC --+ CAST(TENDERCHKAMT AS DECIMAL) AS TSL_GC
,0.00 AS TSL_EPS
,0.00 AS TSL_TND
,0.00 AS TSL_MCRD
,0.00 AS TSL_VISA
,0.00 AS TSL_AMEX
,0.00 AS TSL_DINERS
,0.00 AS TSL_JBC
,0.00 AS TSL_OTCRD
,0.00 AS TSL_SV_CHG
,0.00 AS TSL_OT_CHG
,SUM(CAST(ABS(BEGSI) AS INT)) AS TSL_FT
,SUM(CAST(ABS(LASSI) AS INT)) AS TSL_LT
,SUM(CAST((CAST(QTYREGULAR AS DECIMAL(18,2)) + CAST(QTYSCD20 AS DECIMAL(18,2)) + CAST(QTYSCD5 AS DECIMAL(18,2)) + CAST(QTYPWD AS DECIMAL(18,2)) + CAST(QTYTGOVT AS DECIMAL(18,2)) + CAST(QTYZERORATED AS DECIMAL(18,2))
+ CAST(QTYVATEXEMPT AS DECIMAL(18,2)) + CAST(DISCREGULARQTY AS DECIMAL(18,2)) + CAST(DISCSCD20QTY AS DECIMAL(18,2)) + CAST(DISCSCD5QTY AS DECIMAL(18,2)) + CAST(DISCPWD20QTY AS DECIMAL(18,2))
+ CAST(DISCPWD5QTY AS DECIMAL(18,2)) + CAST(VOIDTRANQTY AS DECIMAL(18,2)) + CAST(ITEMVOIDQTY AS DECIMAL(18,2))*-1 + CAST(TICKETRETQTY AS DECIMAL(18,2))*-1 + CAST(ITEMRETQTY AS DECIMAL(18,2))*-1
+ CAST(ADDLOANTOTQTY AS DECIMAL(18,2))) AS INT)) AS TSL_NT
,SUM(CAST(ABS(BEGSI) AS INT)) AS TSL_BEG_INV
,SUM(CAST(ABS(LASSI) AS INT)) AS TSL_END_INV
,SUM(CAST(QTYREGULAR AS INT)) as TSL_TC_CASH
,SUM(CAST(OTHTENDERSMGCQTY AS INT) + CAST(OTHTENDERSODEXOQTY AS INT)) AS TSL_TC_GC --+ CAST(TENDERCHKQTY AS INT) AS TSL_TC_GC
,0 AS TSL_TC_EPS
,0 AS TSL_TC_TND
,0 AS TSL_TC_MCD
,0 AS TSL_TC_VIS
,0 AS TSL_TC_AMX
,0 AS TSL_TC_DIN
,0 AS TSL_TC_JBC
,0 AS TSL_TC_OC
,#machineno AS TSL_MCH
,0 AS TSL_SRL
,SUM(CAST(ABS(ZCOUNTER) AS INT)) AS TSL_ZCNT
--,LEFT(CONVERT(TIME,GETDATE()),8) AS TSL_TIME
,RIGHT('00'+RTRIM(CAST(DATEPART(HH,GETDATE())AS VARCHAR(5))),2)+RIGHT('00'+RTRIM(CAST(DATEPART(MI,GETDATE()) AS VARCHAR(5))),2)+RIGHT('00'+RTRIM(CAST(DATEPART(SS,GETDATE()) AS VARCHAR(5))),2) AS TSL_TIME
--,SUBSTRING(convert(varchar,WorkDate,111),6,2)+'/'+Right(convert(varchar,WorkDate,111),2)+'/'+left(convert(varchar,WorkDate,111),4) AS TSL_DTE
,SUBSTRING(convert(varchar,WorkDate,111),6,2)+Right(convert(varchar,WorkDate,111),2)+left(convert(varchar,WorkDate,111),4) AS TSL_DTE
FROM dbo.TermZTran t
LEFT JOIN
(SELECT sLessee, sTenantNumber AS TenantCode, sStoreNumber FROM mLandlordStore) tInfo
ON CAST(t.STORE AS INT) = CAST(tInfo.sStoreNumber AS INT)
WHERE CAST(t.Store AS INT) = CAST(#branchcode AS INT)
--AND CAST(t.POS AS int) = CAST(#posno AS int)
AND tInfo.sLessee = #lesseeCode
AND CONVERT(nvarchar(10),t.WorkDate,101) = #trandate
--AND CONVERT(nvarchar(10),t.WorkDate,101) = '04/16/2013' --#trandate
GROUP BY
SALESVATEXEMPT
,ZERORATEDSALEAMT
,ZERORATEDSALETAXVALUE
,WorkDate
) tFinal
--WHERE CAST(BR_CODE AS INT) = CAST('0040' AS INT)
GROUP BY
BR_CODE
,N_CHECK
,CLAS_C
,CLAS_TRD_C
,STOR_NO
,TSL_NEW_A
,TSL_OLD_A
,SalesType
,TSL_DAY_A
,TSL_DIS_A
,TSL_DIS_B
,TSL_DIS_C
,TSL_DIS_D
,TSL_DIS_E
,TSL_Dis_F
,TSL_Dis_G
,TSL_Dis_H
,TSL_Dis_I
,TSL_Dis_J
,TSL_Dis_K
,TSL_Dis_L
,TSL_TAX_A
,TSL_TAX_B
,TSL_ADJ_A
,TSL_ADJ_POS
,TS_ADJ_NEG
,TSL_ADJ_NT_POS
,TSL_ADJ_NT_NEG
,TSL_NET_A
,TSL_VOID
,TSL_RFND
,TSL_TX_SAL
,TSL_NX_SAL
,TSL_CHG
,TSL_CSH
,TSL_GC
,TSL_EPS
,TSL_TND
,TSL_MCRD
,TSL_VISA
,TSL_AMEX
,TSL_DINERS
,TSL_JBC
,TSL_OTCRD
,TSL_SV_CHG
,TSL_OT_CHG
,TSL_FT
,TSL_LT
,TSL_NT
,TSL_BEG_INV
,TSL_END_INV
,TSL_TC_CASH
,TSL_TC_GC
,TSL_TC_EPS
,TSL_TC_TND
,TSL_TC_MCD
,TSL_TC_VIS
,TSL_TC_AMX
,TSL_TC_DIN
,TSL_TC_JBC
,TSL_TC_OC
,TSL_MCH
,TSL_SRL
,TSL_ZCNT
,TSL_TIME
,TSL_DTE) dt
GROUP BY
dt.BR_CODE
,dt.CLAS_C
,dt.CLAS_TRD_C
,dt.N_CHECK
,dt.STOR_NO
,dt.SalesType
,TSL_DAY_A
,TSL_DIS_A
,TSL_DIS_B
,TSL_DIS_C
,TSL_DIS_D
,TSL_DIS_E
,TSL_Dis_F
,TSL_Dis_G
,TSL_Dis_H
,TSL_Dis_I
,TSL_Dis_J
,TSL_Dis_K
,TSL_Dis_L
,TSL_TAX_A
,TSL_TAX_B
,TSL_ADJ_A
,TSL_ADJ_POS
,TS_ADJ_NEG
,TSL_ADJ_NT_POS
,TSL_ADJ_NT_NEG
,TSL_NET_A
,TSL_VOID
,TSL_RFND
,TSL_TX_SAL
,TSL_NX_SAL
,TSL_CHG
,TSL_CSH
,TSL_GC
,TSL_EPS
,TSL_TND
,TSL_MCRD
,TSL_VISA
,TSL_AMEX
,TSL_DINERS
,TSL_JBC
,TSL_OTCRD
,TSL_SV_CHG
,TSL_OT_CHG
,TSL_FT
,TSL_LT
,TSL_NT
,TSL_BEG_INV
,TSL_END_INV
,TSL_TC_CASH
,TSL_TC_GC
,TSL_TC_EPS
,TSL_TC_TND
,TSL_TC_MCD
,TSL_TC_VIS
,TSL_TC_AMX
,TSL_TC_DIN
,TSL_TC_JBC
,TSL_TC_OC
,TSL_MCH
,TSL_SRL
,TSL_ZCNT
,TSL_TIME
,TSL_DTE
Here's a script to create the sample tables and data
USE [LandLord]
GO
/****** Object: Table [dbo].[mLandlordStore] Script Date: 04/25/2013 20:21:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[mLandlordStore](
[IDNumber] [int] IDENTITY(1,1) NOT NULL,
[sStoreNumber] [nvarchar](50) NOT NULL,
[sLessee] [nvarchar](50) NOT NULL,
[sLesseeNumber] [int] NOT NULL,
[sHOGenerated] [varchar](1) NOT NULL,
[LastTranNo] [int] NULL,
[sSpace] [nvarchar](50) NULL,
[sMallCode] [nvarchar](20) NULL,
[sTenantNumber] [nvarchar](20) NULL,
[sClassCode] [nvarchar](20) NULL,
[sTradeCode] [nvarchar](20) NULL,
[sOutletNumber] [nvarchar](20) NULL,
[nSaleType] [int] NULL,
[BatchCount] [int] NULL
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[mLandlordStore] ON
INSERT [dbo].[mLandlordStore] ([IDNumber], [sStoreNumber], [sLessee], [sLesseeNumber], [sHOGenerated], [LastTranNo], [sSpace], [sMallCode], [sTenantNumber], [sClassCode], [sTradeCode], [sOutletNumber], [nSaleType], [BatchCount]) VALUES (1, N'40', N'SMCOIN', 11002558, N'Y', 0, N'01', N'72', N'011002559', N'01', N'SAP', N'03', 1, 0)
INSERT [dbo].[mLandlordStore] ([IDNumber], [sStoreNumber], [sLessee], [sLesseeNumber], [sHOGenerated], [LastTranNo], [sSpace], [sMallCode], [sTenantNumber], [sClassCode], [sTradeCode], [sOutletNumber], [nSaleType], [BatchCount]) VALUES (3, N'1033', N'SMCOIN', 103312345, N'Y', 0, N'01', N'73', N'7312345', N'01', N'SAP', N'04', 1, 0)
INSERT [dbo].[mLandlordStore] ([IDNumber], [sStoreNumber], [sLessee], [sLesseeNumber], [sHOGenerated], [LastTranNo], [sSpace], [sMallCode], [sTenantNumber], [sClassCode], [sTradeCode], [sOutletNumber], [nSaleType], [BatchCount]) VALUES (4, N'1133', N'ACI', 113312345, N'Y', 0, N'01', N'74', N'7412345', N'01', N'SAP', N'05', 1, 0)
INSERT [dbo].[mLandlordStore] ([IDNumber], [sStoreNumber], [sLessee], [sLesseeNumber], [sHOGenerated], [LastTranNo], [sSpace], [sMallCode], [sTenantNumber], [sClassCode], [sTradeCode], [sOutletNumber], [nSaleType], [BatchCount]) VALUES (5, N'1233', N'ALI', 123312345, N'Y', 0, N'01', N'75', N'7512345', N'01', N'SAP', N'06', 1, 0)
INSERT [dbo].[mLandlordStore] ([IDNumber], [sStoreNumber], [sLessee], [sLesseeNumber], [sHOGenerated], [LastTranNo], [sSpace], [sMallCode], [sTenantNumber], [sClassCode], [sTradeCode], [sOutletNumber], [nSaleType], [BatchCount]) VALUES (6, N'1333', N'MWC', 133312345, N'Y', 0, N'01', N'76', N'7612345', N'01', N'SAP', N'07', 1, 0)
INSERT [dbo].[mLandlordStore] ([IDNumber], [sStoreNumber], [sLessee], [sLesseeNumber], [sHOGenerated], [LastTranNo], [sSpace], [sMallCode], [sTenantNumber], [sClassCode], [sTradeCode], [sOutletNumber], [nSaleType], [BatchCount]) VALUES (7, N'1433', N'OCLP', 143312345, N'Y', 0, N'01', N'77', N'7712345', N'01', N'SAP', N'08', 1, 0)
INSERT [dbo].[mLandlordStore] ([IDNumber], [sStoreNumber], [sLessee], [sLesseeNumber], [sHOGenerated], [LastTranNo], [sSpace], [sMallCode], [sTenantNumber], [sClassCode], [sTradeCode], [sOutletNumber], [nSaleType], [BatchCount]) VALUES (8, N'1533', N'RLC', 153312345, N'Y', 0, N'01', N'78', N'7812345', N'01', N'SAP', N'09', 1, 0)
INSERT [dbo].[mLandlordStore] ([IDNumber], [sStoreNumber], [sLessee], [sLesseeNumber], [sHOGenerated], [LastTranNo], [sSpace], [sMallCode], [sTenantNumber], [sClassCode], [sTradeCode], [sOutletNumber], [nSaleType], [BatchCount]) VALUES (9, N'1633', N'SLE', 163312345, N'Y', 0, N'01', N'79', N'7912345', N'01', N'SAP', N'10', 1, 0)
INSERT [dbo].[mLandlordStore] ([IDNumber], [sStoreNumber], [sLessee], [sLesseeNumber], [sHOGenerated], [LastTranNo], [sSpace], [sMallCode], [sTenantNumber], [sClassCode], [sTradeCode], [sOutletNumber], [nSaleType], [BatchCount]) VALUES (10, N'1733', N'STAR', 173312345, N'Y', 0, N'01', N'80', N'8012345', N'01', N'SAP', N'11', 1, 0)
INSERT [dbo].[mLandlordStore] ([IDNumber], [sStoreNumber], [sLessee], [sLesseeNumber], [sHOGenerated], [LastTranNo], [sSpace], [sMallCode], [sTenantNumber], [sClassCode], [sTradeCode], [sOutletNumber], [nSaleType], [BatchCount]) VALUES (11, N'1833', N'WM', 183312345, N'Y', 0, N'01', N'81', N'8112345', N'01', N'SAP', N'12', 1, 0)
INSERT [dbo].[mLandlordStore] ([IDNumber], [sStoreNumber], [sLessee], [sLesseeNumber], [sHOGenerated], [LastTranNo], [sSpace], [sMallCode], [sTenantNumber], [sClassCode], [sTradeCode], [sOutletNumber], [nSaleType], [BatchCount]) VALUES (12, N'1933', N'FSI', 193312345, N'Y', 0, N'01', N'82', N'8212345', N'01', N'SAP', N'13', 1, 0)
SET IDENTITY_INSERT [dbo].[mLandlordStore] OFF
/****** Object: Default [DF_mLandlordStore_LastTranNo] Script Date: 04/25/2013 20:21:42 ******/
ALTER TABLE [dbo].[mLandlordStore] ADD CONSTRAINT [DF_mLandlordStore_LastTranNo] DEFAULT ((1)) FOR [LastTranNo]
GO
USE [LandLord]
GO
/****** Object: Table [dbo].[TermZTran] Script Date: 04/25/2013 20:19:54 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[TermZTran](
[HeaderID] [uniqueidentifier] NOT NULL,
[WorkDate] [smalldatetime] NOT NULL,
[ProcessDate] [smalldatetime] NOT NULL,
[ProcessMode] [nvarchar](10) NOT NULL,
[POSCount] [int] NULL,
[SalePharma] [money] NULL,
[SaleNonPharma] [money] NULL,
[VoidAmount] [money] NULL,
[VoidCount] [int] NULL,
[ZCOUNTER] [nvarchar](4000) NULL,
[STORE] [nvarchar](4000) NULL,
[POS] [nvarchar](4000) NULL,
[DATE] [nvarchar](300) NULL,
[TIME] [nvarchar](300) NULL,
[OGTOTAL] [nvarchar](300) NULL,
[NGTOTAL] [nvarchar](300) NULL,
[BEGSI] [nvarchar](300) NULL,
[LASSI] [nvarchar](300) NULL,
[TSALES] [nvarchar](300) NULL,
[QTYREGULAR] [nvarchar](300) NULL,
[SALESREGULAR] [nvarchar](300) NULL,
[QTYSCD20] [nvarchar](300) NULL,
[SALESCD20] [nvarchar](300) NULL,
[QTYSCD5] [nvarchar](300) NULL,
[SALESCD5] [nvarchar](300) NULL,
[QTYPWD] [nvarchar](300) NULL,
[SALEPWD] [nvarchar](300) NULL,
[QTYTGOVT] [nvarchar](300) NULL,
[SALESTGOVT] [nvarchar](300) NULL,
[QTYZERORATED] [nvarchar](300) NULL,
[SALESZERORATED] [nvarchar](300) NULL,
[QTYVATEXEMPT] [nvarchar](300) NULL,
[SALESVATEXEMPT] [nvarchar](300) NULL,
[TDISCOUNT] [nvarchar](300) NULL,
[DISCREGULARQTY] [nvarchar](300) NULL,
[DISCREGULARAMT] [nvarchar](300) NULL,
[DISCSCD20QTY] [nvarchar](300) NULL,
[DISCSCD20AMT] [nvarchar](300) NULL,
[DISCSCD5QTY] [nvarchar](300) NULL,
[DISCSCD5AMT] [nvarchar](300) NULL,
[DISCPWD20QTY] [nvarchar](300) NULL,
[DISCPWD20AMT] [nvarchar](300) NULL,
[DISCPWD5QTY] [nvarchar](300) NULL,
[DISCPWD5AMT] [nvarchar](300) NULL,
[DNETSALES] [nvarchar](300) NULL,
[DGROSSSALES] [nvarchar](300) NULL,
[SALESACCOUNTABILITY] [nvarchar](300) NULL,
[VOIDTRANQTY] [nvarchar](300) NULL,
[VOIDTRANAMT] [nvarchar](300) NULL,
[ITEMVOIDQTY] [nvarchar](300) NULL,
[ITEMVOIDAMT] [nvarchar](300) NULL,
[TICKETRETQTY] [nvarchar](300) NULL,
[TICKETRETAMT] [nvarchar](300) NULL,
[ITEMRETQTY] [nvarchar](300) NULL,
[ITEMRETAMT] [nvarchar](300) NULL,
[ADDLOANTOTQTY] [nvarchar](300) NULL,
[ADDLOANTOTAMT] [nvarchar](300) NULL,
[TENDERCASHQTY] [nvarchar](300) NULL,
[TENDERCASHAMT] [nvarchar](300) NULL,
[TENDERATMOFFLINEQTY] [nvarchar](300) NULL,
[TENDERATMOFFLINEAMT] [nvarchar](300) NULL,
[TENDERCHRGOFFLINEQTY] [nvarchar](300) NULL,
[TENDERCHRGOFFLINEAMT] [nvarchar](300) NULL,
[TENDERCHKQTY] [nvarchar](300) NULL,
[TENDERCHKAMT] [nvarchar](300) NULL,
[TENDERBDOREBATESQTY] [nvarchar](300) NULL,
[TENDERBDOREBATESAMT] [nvarchar](300) NULL,
[OVERTENDERQTY] [nvarchar](300) NULL,
[OVERTENDERAMT] [nvarchar](300) NULL,
[OTHERTENDERQTY] [nvarchar](300) NULL,
[OTHERTENDERAMT] [nvarchar](300) NULL,
[TENDERCCMQTY] [nvarchar](300) NULL,
[TENDERCCMAMT] [nvarchar](300) NULL,
[TENDERARCODQTY] [nvarchar](300) NULL,
[TENDERARCODAMT] [nvarchar](300) NULL,
[TENDERADBQTY] [nvarchar](300) NULL,
[TENDERADBAMT] [nvarchar](300) NULL,
[TENDERFWV5QTY] [nvarchar](300) NULL,
[TENDERFWV5AMT] [nvarchar](300) NULL,
[TENDEREWT1QTY] [nvarchar](300) NULL,
[TENDEREWT1AMT] [nvarchar](300) NULL,
[TENDERTOP20KQTY] [nvarchar](300) NULL,
[TENDERTOP20KAMT] [nvarchar](300) NULL,
[CCARDATMCHRGONLINEQTY] [nvarchar](300) NULL,
[CCARDATMCHRGONLINEAMT] [nvarchar](300) NULL,
[OTHTENDERSMGCQTY] [nvarchar](300) NULL,
[OTHTENDERSMGCAMT] [nvarchar](300) NULL,
[OTHTENDERSODEXOQTY] [nvarchar](300) NULL,
[OTHTENDERSODEXOAMT] [nvarchar](300) NULL,
[OTHTENDERCORPACCQTY] [nvarchar](300) NULL,
[OTHTENDERCORPACCAMT] [nvarchar](300) NULL,
[OTHTENDERDIFFEREDQTY] [nvarchar](300) NULL,
[OTHTENDERDIFFEREDAMT] [nvarchar](300) NULL,
[TENDERTOTAL] [nvarchar](300) NULL,
[VATSALEAMT] [nvarchar](300) NULL,
[VATSALETAXVALUE] [nvarchar](300) NULL,
[VATEXSALEAMT] [nvarchar](300) NULL,
[VATEXSALETAXVALUE] [nvarchar](300) NULL,
[ZERORATEDSALEAMT] [nvarchar](300) NULL,
[ZERORATEDSALETAXVALUE] [nvarchar](300) NULL,
[TOTALAMT] [nvarchar](300) NULL,
[TOTALTAXVALUE] [nvarchar](300) NULL
) ON [PRIMARY]
GO
INSERT [dbo].[TermZTran] ([HeaderID], [WorkDate], [ProcessDate], [ProcessMode], [POSCount], [SalePharma], [SaleNonPharma], [VoidAmount], [VoidCount], [ZCOUNTER], [STORE], [POS], [DATE], [TIME], [OGTOTAL], [NGTOTAL], [BEGSI], [LASSI], [TSALES], [QTYREGULAR], [SALESREGULAR], [QTYSCD20], [SALESCD20], [QTYSCD5], [SALESCD5], [QTYPWD], [SALEPWD], [QTYTGOVT], [SALESTGOVT], [QTYZERORATED], [SALESZERORATED], [QTYVATEXEMPT], [SALESVATEXEMPT], [TDISCOUNT], [DISCREGULARQTY], [DISCREGULARAMT], [DISCSCD20QTY], [DISCSCD20AMT], [DISCSCD5QTY], [DISCSCD5AMT], [DISCPWD20QTY], [DISCPWD20AMT], [DISCPWD5QTY], [DISCPWD5AMT], [DNETSALES], [DGROSSSALES], [SALESACCOUNTABILITY], [VOIDTRANQTY], [VOIDTRANAMT], [ITEMVOIDQTY], [ITEMVOIDAMT], [TICKETRETQTY], [TICKETRETAMT], [ITEMRETQTY], [ITEMRETAMT], [ADDLOANTOTQTY], [ADDLOANTOTAMT], [TENDERCASHQTY], [TENDERCASHAMT], [TENDERATMOFFLINEQTY], [TENDERATMOFFLINEAMT], [TENDERCHRGOFFLINEQTY], [TENDERCHRGOFFLINEAMT], [TENDERCHKQTY], [TENDERCHKAMT], [TENDERBDOREBATESQTY], [TENDERBDOREBATESAMT], [OVERTENDERQTY], [OVERTENDERAMT], [OTHERTENDERQTY], [OTHERTENDERAMT], [TENDERCCMQTY], [TENDERCCMAMT], [TENDERARCODQTY], [TENDERARCODAMT], [TENDERADBQTY], [TENDERADBAMT], [TENDERFWV5QTY], [TENDERFWV5AMT], [TENDEREWT1QTY], [TENDEREWT1AMT], [TENDERTOP20KQTY], [TENDERTOP20KAMT], [CCARDATMCHRGONLINEQTY], [CCARDATMCHRGONLINEAMT], [OTHTENDERSMGCQTY], [OTHTENDERSMGCAMT], [OTHTENDERSODEXOQTY], [OTHTENDERSODEXOAMT], [OTHTENDERCORPACCQTY], [OTHTENDERCORPACCAMT], [OTHTENDERDIFFEREDQTY], [OTHTENDERDIFFEREDAMT], [TENDERTOTAL], [VATSALEAMT], [VATSALETAXVALUE], [VATEXSALEAMT], [VATEXSALETAXVALUE], [ZERORATEDSALEAMT], [ZERORATEDSALETAXVALUE], [TOTALAMT], [TOTALTAXVALUE]) VALUES (N'35a9637c-4342-4cb4-8f10-1c1d52b09cd4', CAST(0xA1A20000 AS SmallDateTime), CAST(0xA1A80478 AS SmallDateTime), N'sqljob', 1, 0.0000, 0.0000, 0.0000, 0, N'0001', N'0040', N'001', N'16/04/2013', N'19:06', N'0.00', N'73420.22', N'0000000001', N'0000000078', N'69827.81', N'75', N'48543.85', N'7', N'15683.96', N'4', N'940.00', N'6', N'4520.00', N'0', N'0.00', N'0', N'0.00', N'1', N'140.00', N'8283.98', N'30', N'4361.04', N'7', N'3136.79', N'4', N'41.96', N'3', N'723.21', N'3', N'20.98', N'56502.49', N'73420.22', N'61760.30', N'3', N'5815.95', N'-33', N'-1282.50', N'-14', N'-5886.00', N'-151', N'-3923.18', N'2', N'6000.00', N'68', N'46045.65', N'1', N'67.50', N'3', N'751.75', N'1', N'3200.00', N'2', N'310.82', N'2', N'-3.00', N'3', N'0.03', N'0', N'0.00', N'0', N'0.00', N'0', N'0', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'11', N'9096.12', N'5', N'800.00', N'5', N'450.00', N'1', N'1041.43', N'0', N'0.00', N'61760.30', N'43815.32', N'5257.81', N'15823.96', N'0.00', N'0.00', N'0.00', N'59639.28', N'5257.81')
INSERT [dbo].[TermZTran] ([HeaderID], [WorkDate], [ProcessDate], [ProcessMode], [POSCount], [SalePharma], [SaleNonPharma], [VoidAmount], [VoidCount], [ZCOUNTER], [STORE], [POS], [DATE], [TIME], [OGTOTAL], [NGTOTAL], [BEGSI], [LASSI], [TSALES], [QTYREGULAR], [SALESREGULAR], [QTYSCD20], [SALESCD20], [QTYSCD5], [SALESCD5], [QTYPWD], [SALEPWD], [QTYTGOVT], [SALESTGOVT], [QTYZERORATED], [SALESZERORATED], [QTYVATEXEMPT], [SALESVATEXEMPT], [TDISCOUNT], [DISCREGULARQTY], [DISCREGULARAMT], [DISCSCD20QTY], [DISCSCD20AMT], [DISCSCD5QTY], [DISCSCD5AMT], [DISCPWD20QTY], [DISCPWD20AMT], [DISCPWD5QTY], [DISCPWD5AMT], [DNETSALES], [DGROSSSALES], [SALESACCOUNTABILITY], [VOIDTRANQTY], [VOIDTRANAMT], [ITEMVOIDQTY], [ITEMVOIDAMT], [TICKETRETQTY], [TICKETRETAMT], [ITEMRETQTY], [ITEMRETAMT], [ADDLOANTOTQTY], [ADDLOANTOTAMT], [TENDERCASHQTY], [TENDERCASHAMT], [TENDERATMOFFLINEQTY], [TENDERATMOFFLINEAMT], [TENDERCHRGOFFLINEQTY], [TENDERCHRGOFFLINEAMT], [TENDERCHKQTY], [TENDERCHKAMT], [TENDERBDOREBATESQTY], [TENDERBDOREBATESAMT], [OVERTENDERQTY], [OVERTENDERAMT], [OTHERTENDERQTY], [OTHERTENDERAMT], [TENDERCCMQTY], [TENDERCCMAMT], [TENDERARCODQTY], [TENDERARCODAMT], [TENDERADBQTY], [TENDERADBAMT], [TENDERFWV5QTY], [TENDERFWV5AMT], [TENDEREWT1QTY], [TENDEREWT1AMT], [TENDERTOP20KQTY], [TENDERTOP20KAMT], [CCARDATMCHRGONLINEQTY], [CCARDATMCHRGONLINEAMT], [OTHTENDERSMGCQTY], [OTHTENDERSMGCAMT], [OTHTENDERSODEXOQTY], [OTHTENDERSODEXOAMT], [OTHTENDERCORPACCQTY], [OTHTENDERCORPACCAMT], [OTHTENDERDIFFEREDQTY], [OTHTENDERDIFFEREDAMT], [TENDERTOTAL], [VATSALEAMT], [VATSALETAXVALUE], [VATEXSALEAMT], [VATEXSALETAXVALUE], [ZERORATEDSALEAMT], [ZERORATEDSALETAXVALUE], [TOTALAMT], [TOTALTAXVALUE]) VALUES (N'35a9637c-4342-4cb4-8f10-1c1d52b09cd4', CAST(0xA1A20000 AS SmallDateTime), CAST(0xA1A80478 AS SmallDateTime), N'sqljob', 2, 0.0000, 0.0000, 0.0000, 0, N'0001', N'0040', N'002', N'16/04/2013', N'19:06', N'0.00', N'60296.14', N'0000000001', N'0000000076', N'58336.24', N'61', N'44770.01', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'7', N'4597.00', N'15', N'8269.23', N'4', N'700.00', N'3890.95', N'17', N'3890.95', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'49572.91', N'60296.14', N'54445.29', N'2', N'186.00', N'-133', N'-3567.50', N'-7', N'-6661.50', N'-90', N'-2085.50', N'2', N'6000.00', N'66', N'39251.01', N'1', N'67.50', N'1', N'149.00', N'0', N'0.00', N'0', N'0.00', N'3', N'-22.68', N'10', N'3989.88', N'0', N'0.00', N'0', N'0.00', N'0', N'0', N'11', N'205.23', N'11', N'41.05', N'13', N'41.05', N'8', N'4323.75', N'9', N'2500.00', N'1', N'100.00', N'2', N'3799.50', N'0', N'0.00', N'54445.29', N'40603.68', N'4872.38', N'700.00', N'0.00', N'8269.23', N'0.00', N'49572.91', N'4872.38')
INSERT [dbo].[TermZTran] ([HeaderID], [WorkDate], [ProcessDate], [ProcessMode], [POSCount], [SalePharma], [SaleNonPharma], [VoidAmount], [VoidCount], [ZCOUNTER], [STORE], [POS], [DATE], [TIME], [OGTOTAL], [NGTOTAL], [BEGSI], [LASSI], [TSALES], [QTYREGULAR], [SALESREGULAR], [QTYSCD20], [SALESCD20], [QTYSCD5], [SALESCD5], [QTYPWD], [SALEPWD], [QTYTGOVT], [SALESTGOVT], [QTYZERORATED], [SALESZERORATED], [QTYVATEXEMPT], [SALESVATEXEMPT], [TDISCOUNT], [DISCREGULARQTY], [DISCREGULARAMT], [DISCSCD20QTY], [DISCSCD20AMT], [DISCSCD5QTY], [DISCSCD5AMT], [DISCPWD20QTY], [DISCPWD20AMT], [DISCPWD5QTY], [DISCPWD5AMT], [DNETSALES], [DGROSSSALES], [SALESACCOUNTABILITY], [VOIDTRANQTY], [VOIDTRANAMT], [ITEMVOIDQTY], [ITEMVOIDAMT], [TICKETRETQTY], [TICKETRETAMT], [ITEMRETQTY], [ITEMRETAMT], [ADDLOANTOTQTY], [ADDLOANTOTAMT], [TENDERCASHQTY], [TENDERCASHAMT], [TENDERATMOFFLINEQTY], [TENDERATMOFFLINEAMT], [TENDERCHRGOFFLINEQTY], [TENDERCHRGOFFLINEAMT], [TENDERCHKQTY], [TENDERCHKAMT], [TENDERBDOREBATESQTY], [TENDERBDOREBATESAMT], [OVERTENDERQTY], [OVERTENDERAMT], [OTHERTENDERQTY], [OTHERTENDERAMT], [TENDERCCMQTY], [TENDERCCMAMT], [TENDERARCODQTY], [TENDERARCODAMT], [TENDERADBQTY], [TENDERADBAMT], [TENDERFWV5QTY], [TENDERFWV5AMT], [TENDEREWT1QTY], [TENDEREWT1AMT], [TENDERTOP20KQTY], [TENDERTOP20KAMT], [CCARDATMCHRGONLINEQTY], [CCARDATMCHRGONLINEAMT], [OTHTENDERSMGCQTY], [OTHTENDERSMGCAMT], [OTHTENDERSODEXOQTY], [OTHTENDERSODEXOAMT], [OTHTENDERCORPACCQTY], [OTHTENDERCORPACCAMT], [OTHTENDERDIFFEREDQTY], [OTHTENDERDIFFEREDAMT], [TENDERTOTAL], [VATSALEAMT], [VATSALETAXVALUE], [VATEXSALEAMT], [VATEXSALETAXVALUE], [ZERORATEDSALEAMT], [ZERORATEDSALETAXVALUE], [TOTALAMT], [TOTALTAXVALUE]) VALUES (N'35a9637c-4342-4cb4-8f10-1c1d52b09cd4', CAST(0xA1A20000 AS SmallDateTime), CAST(0xA1A80478 AS SmallDateTime), N'sqljob', 3, 0.0000, 0.0000, 0.0000, 0, N'0001', N'0040', N'003', N'16/04/2013', N'19:06', N'0.00', N'0.00', N'0000000000', N'0000000000', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0.00', N'0.00', N'0.00', N'1', N'0.01', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0', N'0.00', N'0.00', N'0.00', N'0.00', N'0.00', N'0.00', N'0.00', N'0.00', N'0.00', N'0.00')
Please help...
You have quite weird data schema. Did you try to store numeric values as decimal rather than as nvarchar. Possible this may should help -
SELECT BR_CODE
,N_CHECK
,CLAS_C
,CLAS_TRD_C
,STOR_NO
,SUM(TSL_NEW_A) AS TSL_NEW_A
,SUM(TSL_OLD_A) AS TSL_OLD_A
,SalesType
,SUM(TSL_DAY_A) AS TSL_DAY_A
,SUM(TSL_DIS_A) AS TSL_DIS_A
,TSL_DIS_B = 0
,SUM(TSL_DIS_C) AS TSL_DIS_C
,TSL_DIS_D = 0
,SUM(TSL_DIS_E) AS TSL_DIS_E
,TSL_Dis_F = 0
,TSL_Dis_G = 0
,TSL_Dis_H = 0
,TSL_Dis_I = 0
,TSL_Dis_J = 0
,TSL_Dis_K = 0
,TSL_Dis_L = 0
,SUM(TSL_TAX_A) AS TSL_TAX_A
,TSL_TAX_B = 0
,TSL_ADJ_A = 0
,TSL_ADJ_POS = 0
,TS_ADJ_NEG = 0
,TSL_ADJ_NT_POS = 0
,TSL_ADJ_NT_NEG = 0
,SUM(TSL_NET_A) AS TSL_NET_A
,SUM(TSL_VOID) AS TSL_VOID
,SUM(TSL_RFND) AS TSL_RFND
,SUM(TSL_TX_SAL) AS TSL_TX_SAL
,SUM(TSL_NX_SAL) AS TSL_NX_SAL
,TSL_CHG
,SUM(TSL_CSH) AS TSL_CSH
,SUM(TSL_GC) AS TSL_GC
,TSL_EPS = 0
,TSL_TND = 0
,TSL_MCRD = 0
,TSL_VISA = 0
,TSL_AMEX = 0
,TSL_DINERS = 0
,TSL_JBC = 0
,TSL_OTCRD = 0
,TSL_SV_CHG = 0
,TSL_OT_CHG = 0
,SUM(TSL_FT) AS TSL_FT
,SUM(TSL_LT) AS TSL_LT
,SUM(TSL_NT) AS TSL_NT
,SUM(TSL_BEG_INV) AS TSL_BEG_INV
,SUM(TSL_END_INV) AS TSL_END_INV
,SUM(TSL_TC_CASH) AS TSL_TC_CASH
,SUM(TSL_TC_GC) AS TSL_TC_GC
,TSL_TC_EPS = 0
,TSL_TC_TND = 0
,TSL_TC_MCD = 0
,TSL_TC_VIS = 0
,TSL_TC_AMX = 0
,TSL_TC_DIN = 0
,TSL_TC_JBC = 0
,TSL_TC_OC = 0
,TSL_MCH = 0
,TSL_SRL = 0
,SUM(TSL_ZCNT) AS TSL_ZCNT
,TSL_TIME
,TSL_DTE
FROM(
SELECT
BR_CODE
, N_CHECK
, CLAS_C
, CLAS_TRD_C
, STOR_NO
, SUM(TSL_NEW_A) AS TSL_NEW_A
, SUM(TSL_OLD_A) AS TSL_OLD_A
, SalesType
, SUM(TSL_DAY_A) AS TSL_DAY_A
, SUM(TSL_DIS_A) AS TSL_DIS_A
, SUM(TSL_DIS_C) AS TSL_DIS_C
, SUM(TSL_DIS_E) AS TSL_DIS_E
, SUM(TSL_TAX_A) AS TSL_TAX_A
, SUM(TSL_NET_A) AS TSL_NET_A
, SUM(TSL_VOID) AS TSL_VOID
, SUM(TSL_RFND) AS TSL_RFND
, SUM(TSL_TX_SAL) AS TSL_TX_SAL
, SUM(TSL_NX_SAL) AS TSL_NX_SAL
, TSL_CHG
, SUM(TSL_CSH) AS TSL_CSH
, SUM(TSL_GC) AS TSL_GC
, SUM(TSL_FT) AS TSL_FT
, SUM(TSL_LT) AS TSL_LT
, SUM(TSL_NT) AS TSL_NT
, SUM(TSL_BEG_INV) AS TSL_BEG_INV
, SUM(TSL_END_INV) AS TSL_END_INV
, SUM(TSL_TC_CASH) AS TSL_TC_CASH
, SUM(TSL_TC_GC) AS TSL_TC_GC
, SUM(TSL_ZCNT) AS TSL_ZCNT
, TSL_TIME
, TSL_DTE
FROM (
SELECT
BR_CODE = 0
, N_CHECK = 0
, CLAS_C = 0
, CLAS_TRD_C = 0
, STOR_NO = 0
, TSL_NEW_A = SUM(CAST(NGTOTAL AS DECIMAL(16,2)) + CAST(OGTOTAL AS DECIMAL(16,2)))
, TSL_OLD_A = SUM(CAST(OGTOTAL AS DECIMAL(16,2)))
, SalesType = 0
, SUM(((CAST(SALESREGULAR AS DECIMAL(16,2)) - CAST(SALESVATEXEMPT AS DECIMAL(16,2))) +
CAST(SALESCD20 AS DECIMAL(16,2)) +
CAST(SALESCD5 AS DECIMAL(16,2)) +
CAST(SALEPWD AS DECIMAL(16,2)) +
CAST(SALESTGOVT AS DECIMAL(16,2)) +
CAST(SALESZERORATED AS DECIMAL(16,2)) +
CAST(DISCREGULARAMT AS DECIMAL(16,2)) +
CAST(DISCSCD20AMT AS DECIMAL(16,2)) +
CAST(DISCSCD5AMT AS DECIMAL(16,2)) +
CAST(DISCPWD20AMT AS DECIMAL(16,2)) +
CAST(DISCPWD5AMT AS DECIMAL(16,2)) +
CAST(VOIDTRANAMT AS DECIMAL(16,2)) +
CAST(ITEMVOIDAMT AS DECIMAL(16,2)) +
CAST(TICKETRETAMT AS DECIMAL(16,2)) +
CAST(ITEMRETAMT AS DECIMAL(16,2)))/1.12) + CAST(SALESVATEXEMPT AS DECIMAL(16,2)) AS TSL_DAY_A --SUM(cast(round((cast(TSALES as decimal)/1.12),2) AS DECIMAL(16,2))) AS TSL_DAY_A --Help
,SUM(ABS(CAST(DISCREGULARAMT AS DECIMAL(16,2)))) AS TSL_DIS_A
,SUM(CAST(DISCSCD20AMT AS DECIMAL(16,2)) + CAST(DISCSCD5AMT AS DECIMAL(16,2))) AS TSL_DIS_C
,SUM(CAST(DISCSCD20AMT AS DECIMAL(16,2)) + CAST(DISCSCD5AMT AS DECIMAL(16,2))) AS TSL_DIS_E
,SUM(CAST(VATSALEAMT AS DECIMAL(16,2))) AS TSL_TAX_A
,SUM(CAST(DGROSSSALES AS DECIMAL(16,2)) - CAST(TOTALTAXVALUE AS DECIMAL(16,2))) AS TSL_NET_A --Help
,SUM(CAST(VOIDTRANAMT AS DECIMAL(16,2))) AS TSL_VOID
,SUM(ABS(CAST(ITEMRETAMT AS DECIMAL(16,2)))) AS TSL_RFND
,SUM(((CAST(SALESREGULAR AS DECIMAL(16,2)) + CAST(SALESVATEXEMPT AS DECIMAL(16,2))) +
CAST(SALESCD20 AS DECIMAL(16,2)) +
CAST(SALESCD5 AS DECIMAL(16,2)) +
CAST(SALEPWD AS DECIMAL(16,2)) +
CAST(SALESTGOVT AS DECIMAL(16,2)) +
CAST(SALESZERORATED AS DECIMAL(16,2)) +
CAST(DISCREGULARAMT AS DECIMAL(16,2)) +
CAST(DISCSCD20AMT AS DECIMAL(16,2)) +
CAST(DISCSCD5AMT AS DECIMAL(16,2)) +
CAST(DISCPWD20AMT AS DECIMAL(16,2)) +
CAST(DISCPWD5AMT AS DECIMAL(16,2)) +
CAST(VOIDTRANAMT AS DECIMAL(16,2)) +
CAST(ITEMVOIDAMT AS DECIMAL(16,2)) +
CAST(TICKETRETAMT AS DECIMAL(16,2)) +
CAST(ITEMRETAMT AS DECIMAL(16,2)))) AS TSL_TX_SAL --Help
,(CAST(SALESVATEXEMPT AS DECIMAL(16,2)) + (CAST(ZERORATEDSALEAMT AS DECIMAL(16,2)) - CAST(ZERORATEDSALETAXVALUE AS DECIMAL(16,2)))) AS TSL_NX_SAL
,SUM(CAST(CCARDATMCHRGONLINEAMT AS DECIMAL(16,2))) AS TSL_CHG --Help
,SUM(CAST(TENDERCASHAMT AS DECIMAL(16,2))) AS TSL_CSH
,SUM(CAST(OTHTENDERSMGCAMT AS DECIMAL(16,2)) + CAST(OTHTENDERSODEXOAMT AS DECIMAL(16,2))) AS TSL_GC --+ CAST(TENDERCHKAMT AS DECIMAL) AS TSL_GC
,SUM(CAST(ABS(BEGSI) AS INT)) AS TSL_FT
,SUM(CAST(ABS(LASSI) AS INT)) AS TSL_LT
,SUM(CAST((CAST(QTYREGULAR AS DECIMAL(18,2)) + CAST(QTYSCD20 AS DECIMAL(18,2)) + CAST(QTYSCD5 AS DECIMAL(18,2)) + CAST(QTYPWD AS DECIMAL(18,2)) + CAST(QTYTGOVT AS DECIMAL(18,2)) + CAST(QTYZERORATED AS DECIMAL(18,2))
+ CAST(QTYVATEXEMPT AS DECIMAL(18,2)) + CAST(DISCREGULARQTY AS DECIMAL(18,2)) + CAST(DISCSCD20QTY AS DECIMAL(18,2)) + CAST(DISCSCD5QTY AS DECIMAL(18,2)) + CAST(DISCPWD20QTY AS DECIMAL(18,2))
+ CAST(DISCPWD5QTY AS DECIMAL(18,2)) + CAST(VOIDTRANQTY AS DECIMAL(18,2)) + CAST(ITEMVOIDQTY AS DECIMAL(18,2))*-1 + CAST(TICKETRETQTY AS DECIMAL(18,2))*-1 + CAST(ITEMRETQTY AS DECIMAL(18,2))*-1
+ CAST(ADDLOANTOTQTY AS DECIMAL(18,2))) AS INT)) AS TSL_NT
,SUM(CAST(ABS(BEGSI) AS INT)) AS TSL_BEG_INV
,SUM(CAST(ABS(LASSI) AS INT)) AS TSL_END_INV
,SUM(CAST(QTYREGULAR AS INT)) as TSL_TC_CASH
,SUM(CAST(OTHTENDERSMGCQTY AS INT) + CAST(OTHTENDERSODEXOQTY AS INT)) AS TSL_TC_GC
,SUM(CAST(ABS(ZCOUNTER) AS INT)) AS TSL_ZCNT
,RIGHT('00'+RTRIM(CAST(DATEPART(HH,GETDATE())AS VARCHAR(5))),2)+RIGHT('00'+RTRIM(CAST(DATEPART(MI,GETDATE()) AS VARCHAR(5))),2)+RIGHT('00'+RTRIM(CAST(DATEPART(SS,GETDATE()) AS VARCHAR(5))),2) AS TSL_TIME
,SUBSTRING(convert(varchar,WorkDate,111),6,2)+Right(convert(varchar,WorkDate,111),2)+left(convert(varchar,WorkDate,111),4) AS TSL_DTE
FROM dbo.TermZTran t
LEFT JOIN (
SELECT sLessee, sTenantNumber AS TenantCode, sStoreNumber
FROM mLandlordStore
) tInfo ON t.STORE = tInfo.sStoreNumber
WHERE CAST(t.Store AS INT) = CAST(#branchcode AS INT)
AND tInfo.sLessee = #lesseeCode
AND CONVERT(nvarchar(10),t.WorkDate,101) = #trandate
AND CONVERT(nvarchar(10),t.WorkDate,101) = '04/16/2013'
AND CAST(BR_CODE AS INT) = CAST('0040' AS INT)
GROUP BY
SALESVATEXEMPT
, ZERORATEDSALEAMT
, ZERORATEDSALETAXVALUE
, WorkDate
) tFinal
GROUP BY
BR_CODE
,N_CHECK
,CLAS_C
,CLAS_TRD_C
,STOR_NO
,TSL_NEW_A
,TSL_OLD_A
,SalesType
,TSL_DAY_A
,TSL_DIS_A
,TSL_DIS_C
,TSL_DIS_E
,TSL_TAX_A
,TSL_NET_A
,TSL_VOID
,TSL_RFND
,TSL_TX_SAL
,TSL_NX_SAL
,TSL_CHG
,TSL_CSH
,TSL_GC
,TSL_FT
,TSL_LT
,TSL_NT
,TSL_BEG_INV
,TSL_END_INV
,TSL_TC_CASH
,TSL_TC_GC
,TSL_ZCNT
,TSL_TIME
,TSL_DTE
) dt
GROUP BY
dt.BR_CODE
,dt.CLAS_C
,dt.CLAS_TRD_C
,dt.N_CHECK
,dt.STOR_NO
,dt.SalesType
,TSL_DAY_A
,TSL_DIS_A
,TSL_DIS_C
,TSL_DIS_E
,TSL_TAX_A
,TSL_NET_A
,TSL_VOID
,TSL_RFND
,TSL_TX_SAL
,TSL_NX_SAL
,TSL_CHG
,TSL_CSH
,TSL_GC
,TSL_FT
,TSL_LT
,TSL_NT
,TSL_BEG_INV
,TSL_END_INV
,TSL_TC_CASH
,TSL_TC_GC
,TSL_ZCNT
,TSL_TIME
,TSL_DTE

Resources