
Signature
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
It is now working! My new question is before I was having problems, I was
storing a date in a nvarchar field and a time in another nvarchar field, but
I converted those fields to one datetime field to make searching between
dates easier. When I had the two nvarchar fields, I did not have to enclose
parameters in the WHERE in quotes. Why do I have to do that now?
Thank you so much for correcting my issue.
> > I thought I understood your comments, but still am getting errors:
> >
[quoted text clipped - 30 lines]
>
> in the SQL file.
jbellnewsposts@hotmail.com - 10 Feb 2010 08:02 GMT
>It is now working! My new question is before I was having problems, I was
>storing a date in a nvarchar field and a time in another nvarchar field, but
[quoted text clipped - 38 lines]
>>
>> in the SQL file.
SQL Server is making assumptions as to what it is. I don't know who
how it decides but there are rules for regular identifiers and it may
be related to type precedence.
Using quotes in your SQLCMD script makes sure it knows that it is a
string. If you used '[' and ']' it would be an identifier.
HTH
John
Erland Sommarskog - 10 Feb 2010 08:37 GMT
> It is now working! My new question is before I was having problems, I
> was storing a date in a nvarchar field and a time in another nvarchar
> field, but I converted those fields to one datetime field to make
> searching between dates easier. When I had the two nvarchar fields, I
> did not have to enclose parameters in the WHERE in quotes. Why do I
> have to do that now?
Since I don't see the code, I will have to guess. But if you have
datecol = 20100210
and datecol is nvarchar, there will be an implicit conversion from integer
to nvarchar. And if you use delimited format like:
datecol = 2010/02/10
there will still be an implicit conversion, but it is unlikely that you
will hit any rows, since 2010/02/10 evaluates to 100.

Signature
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