You are here: Re: Convert Sting to Date « MsSQL Server « IT news, forums, messages
Re: Convert Sting to Date

Posted by Erland Sommarskog on 03/02/06 00:45

Crumb (rowan.ian@gmail.com) writes:
> I am a Newbie to SQL and am therefore sorry if this is a stupid
> question
>
> I am trying to run the following command
>
> SELECT OriginationNumber, DestinationNumber, StartTime, State, Duration
> FROM dbo.IpPbxCDR
> WHERE OriginationNumber Like 'MMColParam' or DestinationNumber Like
> 'MMColParam' and StartTime Between '%MMColParam2%' AND
> '%MMColParam3%'
>
> I am passing the variables MMColParam from a Web page but I always get
> the following error when I try to run the command
>
> Error converting string Datetime from Charactor String.
>
> I have checked the DB and the value is defined as DateTime entry
>
> here is an example of Table entry 16/11/2005 18:27:24

Datetime values are not strings, but binary values. Strings can be
implicitly converted to dates, but there is no datetime interpretation
of the string '%MMColParam2%'. I don't know what you intended the
% to mean, but they don't mean anything to SQL Server in this context.

The same goes for

OriginationNumber Like 'MMColParam'

This will give a match if you have an origination number with the exact
of the strnig 'MMColParam'.

Maybe you meant something like:

SELECT OriginationNumber, DestinationNumber, StartTime, State, Duration
FROM dbo.IpPbxCDR
WHERE OriginationNumber Like @MMColParam or
DestinationNumber Like @MMColParam and
StartTime Between @MMColParam2 AND @MMColParam3

Although, you may be thinking of MMcolParam as parameters in your web
page. In such you need to pass them as parameters to SQL.

By the way, what is the intended logic? The above will not consider
StartTime if there is a match in OriginationNumber, only if there is
a match in DestinationNumber.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация