Click here to Skip to main content
15,890,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have a query where i am not been able to find out errors.
SQL
SELECT
  dbo.SalePurchase.tran_date AS billdate
 ,LEFT(dbo.SalePurchase.tran_no, 1) + RIGHT(dbo.SalePurchase.tran_no, 8) AS BILLNO
 ,dbo.GL.AcName, Item_1.ItemName
 ,dbo.IT.iRate
 ,dbo.IT.iAmount AS amt
 ,Item_1.UOM
 ,dbo.IT.iQty
 ,dbo.SalePurchase.sp_dr
 ,AddressBook_1.FullName
 ,dbo.SalePurchase.sp_cr AS bamt
 ,GenMast_1.GenName AS itemgroup
 ,dbo.Item.ItemName AS subitem
 ,dbo.AddressBook.FullName AS tagidar
 ,GenMast_2.GenName AS city
 ,dbo.GenMast.GenName AS district
 ,salepurchase.sp_cr-salepurchase.sp_basic as tamt
FROM
 dbo.AddressBook
 RIGHT OUTER JOIN dbo.GenMast AS GenMast_2
 INNER JOIN dbo.GenMast ON GenMast_2.GroupCd = dbo.GenMast.Code
 RIGHT OUTER JOIN dbo.GL ON GenMast_2.Code = dbo.GL.CityCd ON dbo.AddressBook.Code = dbo.GL.TagadgirCd
 RIGHT OUTER JOIN dbo.SalePurchase ON dbo.GL.AcCode = dbo.SalePurchase.ac_code
 LEFT OUTER JOIN dbo.AddressBook AS AddressBook_1 ON dbo.GL.BrokerCd = AddressBook_1.Code
 LEFT OUTER JOIN dbo.Item
 RIGHT OUTER JOIN dbo.IT ON dbo.Item.Code = dbo.IT.SubItemCd ON dbo.SalePurchase.Code = dbo.IT.SPCode
 LEFT OUTER JOIN dbo.Item AS Item_1
 LEFT OUTER JOIN dbo.GenMast AS GenMast_1 ON Item_1.GroupCd = GenMast_1.Code ON dbo.IT.ItemCode = Item_1.Code
WHERE (salepurchase.sp_type='sr')
ORDER BY LEFT(dbo.SalePurchase.tran_no, 1) + RIGHT(dbo.SalePurchase.tran_no, 8)

n execution showing "unable to convert char to datetime". Although the data type for trandate is set to DateTime. The error remains.

Please help..
Posted
Updated 18-Nov-13 20:51pm
v3
Comments
Mike Meinz 2-Sep-13 17:35pm    
The error is not obvious based on the information you have posted in your question. Are you sure that the error is generated when this SQL statement is executed? is it possible that it is generated by a line of code that is near this SQL code in your program? Try executing this SQL statement in a SQL Server Management Studio query window.

Please use Improve Question and include DDL for SalePurchase, AddressBook, Item, GenMast, GL and IT tables.
coded007 25-Sep-13 1:29am    
Can you please provide table structures so that we can help you better
ArunRajendra 19-Nov-13 3:15am    
I am guessing this to be a data issue.

1 solution

Try to find the place or paster here all places where dates column is used , unable to identify dbo.SalePurchase.sp_dr what is this ? if date is used in this user defined function then figure it out. The problem is you are trying to use date column as string/text either comparing it with wrong entity or using wrong function over it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900