473,416 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

Need to solve this problem, substring('PA-1501200', 4 , 99), sql thinks its a date

Sl1ver
196 100+
i got this
Expand|Select|Wrap|Line Numbers
  1. substring('PA-1501200', 4 , 99)
  2.  
now for some reason i think it sees the number as a date, it should be n varchar and then convert it into a int, then i get this error

Conversion failed when converting datetime from character string.

and here is my sql
the ponumber will be the same as the grid number if i get it to work
Expand|Select|Wrap|Line Numbers
  1. declare @PONumber varchar(50)
  2. declare @GridNumber varchar(50)
  3.  
  4.  
  5. --set @PONumber = 
  6. set @GridNumber = substring('PA-1501200', 4 , 99)
  7.  
  8. select * from int_err_PutAway_writeback
  9. where 
  10. ((refno = @PONumber) and isnull(@PONumber,'') <> '')
  11. or
  12. ((refno = @GridNumber) and isnull(@PONumber,'') = '')
  13. and err_datetime is not null
  14. union all
  15. select *, ' ' ab_res from int_err_Receive_writeback
  16. where 
  17. ((refno = @PONumber) and isnull(@PONumber,'') <> '')
  18. or
  19. ((refno = @GridNumber) and isnull(@PONumber,'') = '')
  20. and err_datetime is not null
  21. union all
  22. select * from int_err_ibtPutAway_writeback
  23. where 
  24. ((refno = @PONumber) and isnull(@PONumber,'') <> '')
  25. or
  26. ((refno = @GridNumber) and isnull(@PONumber,'') = '')
  27. and err_datetime is not null
  28. union all
  29. select *, ' ' ab_res from int_err_ibtReceive_writeback
  30. where 
  31. ((refno = @PONumber) and isnull(@PONumber,'') <> '')
  32. or
  33. ((refno = @GridNumber) and isnull(@PONumber,'') = '')
  34. and err_datetime is not null
  35. order by err_datetime desc
  36.  
Mar 1 '10 #1
1 1067
ck9663
2,878 Expert 2GB
Here are the possible reason for your error:

1. If your code passes the line
Expand|Select|Wrap|Line Numbers
  1.    set @GridNumber = substring('PA-1501200', 4 , 99)
  2.  
then the error is on your select.

2.Your REFNO column is a date data type.

3. One of the field on your table that you're trying to UNIONize is a date and you're trying to UNION it with a char/varchar column.

Happy Coding!!!

~~ CK
Mar 1 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jim | last post by:
I'm having a problem with a date query..im trying to pull customer data based on a date specified from a form to 3 months prior to the date specified. So lets say in the form I specified 1/2/2004....
0
by: Michael England | last post by:
I'm having trouble with the Calendar control in ASP.NET using VB. When I place a calendar on a page and then select a new date, it seems that I have to select the date twice in order for any...
6
by: Federico | last post by:
Hi, this is what I can do: - Create new solutions using VS.Net ASP.Net - Save the solutions, build the solution, view in browser with the solution still open. But, once I close the solution, I...
0
by: Ramakrishnan Nagarajan | last post by:
Hi, I am facing a problem in uploading Excel data to the Database. While uploading my code reads Excel Data using OleDbReader and store into a dataset by looping through the OleDbReader result...
1
by: G Gerard | last post by:
Hello I am having some problem comparing dates with the SQL statement below MySQL = "SELECT Format(Date, 'yyyy/mmmm/dd') as FROM TblDates WHERE _ Format(Date, 'yyyy/mmmm/dd') =...
6
by: Bill Nguyen | last post by:
I'm reading a CSV file with the date colum formatted as "YYMMDD" -"070310" when viewed in notepad or similar trext editor. However, in my app, using ODBCReader, the column value becomes "70310"...
1
by: cjordan | last post by:
Hi everyone. I'm new here, and I think I've got a pretty unique problem (haven't found any solution to this anywhere else), but I'm hoping that someone here can help me. To be honest, I'm not a...
1
by: cooklooks | last post by:
http://www.videoriporter.hu/vr/fs?content=/vr/player/1320/date/count
1
by: disney86 | last post by:
I am setting up Forms in Access 08. I have a form which when opened will auto insert the current time and current date. I need to be able to allow the user to set up paramaters to auto select a...
1
by: Rehana | last post by:
I am having problem,while inserting date using insert query...In front end am using c#.net and my database is in ms-access.. if am pass date in dd/mm/yy format in insert query..it store as mm/dd/yy...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.