all groups > sql server programming > december 2006 >
You're in the

sql server programming

group:

need necessary help pls


need necessary help pls Nassa
12/31/2006 11:11:16 PM
sql server programming:
Hi Everyone,

I have 3 tables
-stocktbl(GSC,title,code),PK:GSC
-invoicedetailtbl(GSC,Comment,quantity,fee,fk_invoicesyscode,Syscode),PK:Syscode,FK:fk_invoicesyscode
-invoicetbl(customername,comment,invoiceserialno,invoicedate),PK:invoiceserialno

I want to find a query of the last date and fee of objects which is
stored in the stocktbl.

Thanks,
Nassa
Re: need necessary help pls Nassa
1/1/2007 12:27:09 AM
Uri Dimant,

The relationships bet. tables are:
dbo.InvoiceTbl LEFT OUTER JOIN
dbo.invoiceDetailTbl ON
dbo.InvoiceTbl.InvoiceSerialNo = dbo.invoiceDetailTbl.FK_InvoiceSysCode
RIGHT OUTER JOIN
dbo.StockTbl ON dbo.invoiceDetailTbl.GoodSysCode
= dbo.StockTbl.GoodSyscode

Thanks,
Nassa




[quoted text, click to view]
Re: need necessary help pls Nassa
1/1/2007 1:15:41 AM
Uri Dimant,

I checked that before but it gives me the wrong result.
for your information:
for example,if I have 4 invoices with the bellow details:
In the invoice1on invoicedate 2006.8.25,goodsyscodes 1,2,3,4,5 have
fees 100,100,100,100,100,respectively.
In the invoice2 on invoicedate 2006.8.28,goodsyscodes 1,3,4,5 have
fees 200,200,200,200,respectively.
In the invoice3 on invoicedate 2006.8.30,goodsyscodes 2,4,3 have fees
300,300,300,respectively.
In the invoice4 on invoicedate 2006.8.28,goodsyscodes 1 have fees 150.

The results that I want:

GoodSysCode LDate LFee
1 2006.8.28 200
2 2006.8.30 300
3 2006.8.30 300
4 2006.8.30 300
5 2006.8.28 200


Thanks,
Nassa


[quoted text, click to view]
Re: need necessary help pls Nassa
1/1/2007 2:22:13 AM
Uri Dimant,

I send it to your e-mail.

Thanks,
Nassa

[quoted text, click to view]
Re: need necessary help pls Nassa
1/1/2007 2:37:02 AM
Uri Dimant,

sorry,can u fill it urself?

Thanks,
Nassa


[quoted text, click to view]
Re: need necessary help pls Uri Dimant
1/1/2007 9:43:36 AM
Nassa
Untested

SELECT stocktbl.GSC,title,code FROM stocktbl JOIN invoicedetailtbl ON
stocktbl.GSC=invoicedetailtbl.stocktbl JOIN invoicetbl ON
invoicedetailtbl.fk_invoicesyscode=invoicetbl.invoiceserialno
WHERE invoicedate=(SELECT MAX(invoicedate) FROM invoicetbl I WHERE
I.invoiceserialno=invoicedetailtbl.fk_invoicesyscode)








[quoted text, click to view]

Re: need necessary help pls Uri Dimant
1/1/2007 10:34:39 AM
Nassa
Try this

The relationships bet. tables are:
dbo.InvoiceTbl LEFT OUTER JOIN
dbo.invoiceDetailTbl ON
dbo.InvoiceTbl.InvoiceSerialNo = dbo.invoiceDetailTbl.FK_InvoiceSysCode
RIGHT OUTER JOIN
dbo.StockTbl ON dbo.invoiceDetailTbl.GoodSysCode
= dbo.StockTbl.GoodSyscode

WHERE invoicedate=(SELECT MAX(invoicedate) FROM invoicetbl I WHERE
I.invoiceserialno=invoicedetailtbl.fk_invoicesyscode)


If it does not help, please post DDL+ sample data + an expected result





[quoted text, click to view]

Re: need necessary help pls Uri Dimant
1/1/2007 11:43:55 AM
Nassa

Please post DDL

CREATE TABLE blblbla (column INT......)
INSERT INTO blbalbla VALUES (1212121)
.......
........





[quoted text, click to view]

Re: need necessary help pls Anith Sen
1/1/2007 12:00:45 PM
Post your table structures, sample data & expected results. For details,
see: www.aspfaq.com/5006

--
Anith

Re: need necessary help pls Uri Dimant
1/1/2007 12:31:33 PM
What's about posting sample data?




[quoted text, click to view]

Re: need necessary help pls Uri Dimant
1/1/2007 12:51:11 PM
I'm really sorry, I have no time right now



[quoted text, click to view]

Re: need necessary help pls Nassa
1/1/2007 8:58:11 PM
Uri dimant,

Thank you so much.here is sample data.
INSERT INTO [hesab].[dbo].[invoiceDetailTbl]
([GoodSysCode]
,[Comment]
,[Quantity]
,[Fee]
,[Unit]
,[UnitRate]
,[UserPrice]
,[SerialNo]
,[Size]
,[Color]
,[WareHouse]
,[FK_InvoiceSysCode]
,[DiscountPercent]
,[Term]
,[RowNo])
VALUES
(<GoodSysCode, int,>
,<Comment, nvarchar(300),>
,<Quantity, float,>
,<Fee, money,>
,<Unit, nvarchar(100),>
,<UnitRate, float,>
,<UserPrice, money,>
,<SerialNo, nvarchar(100),>
,<Size, int,>
,<Color, int,>
,<WareHouse, int,>
,<FK_InvoiceSysCode, int,>
,<DiscountPercent, float,>
,<Term, nvarchar(1000),>
,<RowNo, int,>)
------------------------------------------------------------------------------------
INSERT INTO [hesab].[dbo].[InvoiceTbl]
([CustomerName]
,[FK_AccountSysCode]
,[Comment]
,[RecivedDate]
,[DelivaredDate]
,[PaymentDate]
,[InvoiceDate]
,[FK_DocsysCode]
,[ArchiveName]
,[UserNo]
,[InvoiceNo]
,[VisitorSyscode]
,[VisitorPer]
,[VisitorAmount]
,[SysDate]
,[Sign]
,[Type]
,[Amani])
VALUES
(<CustomerName, nvarchar(300),>
,<FK_AccountSysCode, int,>
,<Comment, nvarchar(300),>
,<RecivedDate, char(8),>
,<DelivaredDate, char(8),>
,<PaymentDate, char(8),>
,<InvoiceDate, char(8),>
,<FK_DocsysCode, int,>
,<ArchiveName, nvarchar(100),>
,<UserNo, int,>
,<InvoiceNo, int,>
,<VisitorSyscode, int,>
,<VisitorPer, real(24,0),>
,<VisitorAmount, money,>
,<SysDate, datetime,>
,<Sign, int,>
,<Type, int,>
,<Amani, bit,>)
------------------------------------------------------------------------------------
INSERT INTO [hesab].[dbo].[StockTbl]
([Title]
,[Code]
,[BarCode]
,[Type]
,[FstUnit]
,[SecUnit]
,[UnitRate]
,[OrderPoint]
,[SalePrice1]
,[SalePrice2]
,[SalePrice3]
,[SalePrice4]
,[SalePrice5]
,[VisitorPer]
,[Comment]
,[DiscontPer]
,[UserPrice]
,[GroupID1]
,[GroupID2]
,[SerialNo]
,[Weight]
,[Term])
VALUES
(<Title, nvarchar(1000),>
,<Code, nvarchar(100),>
,<BarCode, nvarchar(100),>
,<Type, int,>
,<FstUnit, nvarchar(100),>
,<SecUnit, nvarchar(100),>
,<UnitRate, float,>
,<OrderPoint, real(24,0),>
,<SalePrice1, money,>
,<SalePrice2, money,>
,<SalePrice3, money,>
,<SalePrice4, money,>
,<SalePrice5, money,>
,<VisitorPer, float,>
,<Comment, nvarchar(300),>
,<DiscontPer, float,>
,<UserPrice, money,>
,<GroupID1, int,>
,<GroupID2, int,>
,<SerialNo, bit,>
,<Weight, real(24,0),>
,<Term, nvarchar(1000),>)

does it help u?
please help me,I really need it.

Thanks.
Nassa

[quoted text, click to view]
Re: need necessary help pls Nassa
1/2/2007 12:35:15 AM
Uri Dimant,

do you get it?
I really need it now also I found a solution but its query cost is 64%
and its too high.

Thanks,
Nassa

[quoted text, click to view]
Re: need necessary help pls Nassa
1/2/2007 8:51:10 PM
Hugo Kornelis,

Thank you for your info.
I found the results.
Have fun,

Thanks,
Nassa

[quoted text, click to view]
Re: need necessary help pls Hugo Kornelis
1/3/2007 1:07:39 AM
[quoted text, click to view]

Hi Nassa,

Probably not, because there's no real data there. I couldn't run your
script because you have sent the table DDL to Uri's mail, but even with
the CREATE TABLE statements, I'd just get errors for running the INSERT
statemtents you posted.

If you want help, youu reallly have to post the following to the
newsgroup:

* CREATE TABLE statements for all tables involved. You may omit columns
that are irrelevant for the problem, but do include all constraints,
properties, and indexes!

* INSERT statements with sample data that illustrates the problem. Make
sure to use locale-independant format for dates (yyyymmdd).

* Expected results.

Also, create a new, empty database on your own server, run the CREATE
TABLE and INSERT statements, and correct any errors before posting them.

If you need more help assembling the information for your next post,
please consult www.aspfaq.com/5006.

--
Hugo Kornelis, SQL Server MVP
AddThis Social Bookmark Button