Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 DateTime Field

Author  Topic 

terig
Starting Member

3 Posts

Posted - 2010-08-19 : 14:47:37
Hi All,

Can anyone tell me what I am doing wrong in the code below:


('Resolution #: ' + ISNULL(ResoNum, '') + CHAR(10) + 'Ordinance #: ' + CAST(ISNULL(OrdNum,'') AS VARCHAR) + CHAR(10) + 'Annexation Date: '+ CONVERT(VARCHAR, FinalDate, 107)

The error message I receive is as follows:

---------------------------
Autodesk MapGuide Server error : 529-230
---------------------------
Unable to retrieve data for layer "Annexations". The query posed to data source "Cupertino_SHP" failed to execute. The method SetCommandText() on the ICommandText interface failed using the following SQL: SELECT ID, FEATURE_GEOM, ('Resolution #: ' + ISNULL(ResoNum, '') + CHAR(10) + 'Ordinance #: ' + CAST(ISNULL(OrdNum,'') AS VARCHAR) + CHAR(10) + 'Annexation Date: '+ CONVERT(VARCHAR, FinalDate, 107) FROM Annexation. SQL statement: SELECT ID, FEATURE_GEOM, ('Resolution #: ' + ISNULL(ResoNum, '') + CHAR(10) + 'Ordinance #: ' + CAST(ISNULL(OrdNum,'') AS VARCHAR) + CHAR(10) + 'Annexation Date: '+ CONVERT(VARCHAR, FinalDate, 107) FROM Annexation.

For further information please contact terig@cupertino.org
---------------------------
OK
---------------------------

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-19 : 14:50:33
sorry i dont think you've posted full query. i cant see the table specified in error message in actual query

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

terig
Starting Member

3 Posts

Posted - 2010-08-24 : 10:57:27
This query is used to label a layer's features in a mapping application the table was called out in a different area. This part of the code works

('Resolution #: ' + ISNULL(ResoNum, '') + CHAR(10) + 'Ordinance #: ' + CAST(ISNULL(OrdNum,'') AS VARCHAR) + CHAR(10) + 'Annexation Date: ' + CAST(ISNULL(FinalDate,'') AS VARCHAR))

But I need to remove the time from the "FinalDate" field so I found a code that works:

CONVERT(VARCHAR, FinalDate, 107)

But I need these lines of code to work together any suggestions?


Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-08-24 : 11:15:23
Maybe:
('Resolution #: ' + ISNULL(ResoNum, '') + CHAR(10) + 'Ordinance #: ' + CAST(ISNULL(OrdNum,'') AS VARCHAR) + CHAR(10) + 'Annexation Date: ' + ISNULL(CONVERT(VARCHAR, FinalDate, 107),''))


Also, it's bad practice to cast things to a type that requires a length specification and not include it. Like casting to a VARCHAR for example.
Go to Top of Page

terig
Starting Member

3 Posts

Posted - 2010-08-24 : 18:38:30
That worked! Thank you sooooo much.
Go to Top of Page
   

- Advertisement -