Showing posts with label char. Show all posts
Showing posts with label char. Show all posts

Friday, March 23, 2012

Incorrect syntax near comparison on parameter value

Error: Incorrect syntax near '@.today'.

DECLARE @.today CHAR(8)

SET @.today = CONVERT(CHAR(8), GETDATE(), 112)

SELECT c.name,

c.cust,

m.num,

ph.Entered

FROM Master m (NOLOCK)

INNER JOIN dbo.hisy ph ON ph.number = m.num

INNER JOIN dbo.Cust c ON c.Cust = m.Cust

WHERE m.customer IN (0000162, 0000164)

AND ph.Entered IS NOT NULL

AND CONVERT(CHAR(8), ph.Entered, 112) = @.today <-Error is here

It passes syntax checking for me. Is this the entire batch?

If I add a BEGIN before the statement, I get the syntax error two. Sometimes SQL Server error messages are really misleading, though it is technically correct.

|||thanks I was missign the END, that was it.

Friday, March 9, 2012

incomprshensible code

Hello

My friend gave me stored procedure, and I understand this code:

create table t (x varchar(50), y int)
insert into t (x)
select 'bob' + char(1) + 'fred'
select * from t

Please explain me and corect this code.

AndrzejOn Wed, 14 Nov 2007 11:05:00 -0800, J?dru? <anowacki.pila@.interia.pl>
wrote:

Quote:

Originally Posted by

>Hello
>
>My friend gave me stored procedure, and I understand this code:
>
>create table t (x varchar(50), y int)


Create an empty table. The table has two columns, one varying length
and one integer.

Quote:

Originally Posted by

>insert into t (x)


We are going to INSERT new rows(s) into the table, but only assign
data to the column named x.

Quote:

Originally Posted by

>select 'bob' + char(1) + 'fred'


The source of data for the INSERT is the result set of a SELECT. The
SELECT does not read any table, it just returns one row. The one
column in the result set is a character string made up by
concatenating (using the + operator) three other strings. The string
in the middle is created using the CHAR function. The CHAR function
converts a number ranging from 0 to 255 into an ASCII character. The
ASCII character that corresponds to 1 is not a printable character;
for me the results look like an empty square.

Quote:

Originally Posted by

>select * from t


This returns the one row of the table.
x y
---------------- ----
bob
fred NULL

Quote:

Originally Posted by

>Please explain me and corect this code.


The code is correct, though it looks like a simple example of
something rather than anything of actual use.

Roy Harvey
Beacon Falls, CT|||On 14 Lis, 21:03, "Roy Harvey (SQL Server MVP)" <roy_har...@.snet.net>
wrote:

Quote:

Originally Posted by

On Wed, 14 Nov 2007 11:05:00 -0800, J?dru? <anowacki.p...@.interia.pl>
wrote:
>

Quote:

Originally Posted by

Hello


>

Quote:

Originally Posted by

My friend gave me stored procedure, and I understand this code:


>

Quote:

Originally Posted by

create table t (x varchar(50), y int)


>
Create an empty table. The table has two columns, one varying length
and one integer.
>

Quote:

Originally Posted by

insert into t (x)


>
We are going to INSERT new rows(s) into the table, but only assign
data to the column named x.
>

Quote:

Originally Posted by

select 'bob' + char(1) + 'fred'


>
The source of data for the INSERT is the result set of a SELECT. The
SELECT does not read any table, it just returns one row. The one
column in the result set is a character string made up by
concatenating (using the + operator) three other strings. The string
in the middle is created using the CHAR function. The CHAR function
converts a number ranging from 0 to 255 into an ASCII character. The
ASCII character that corresponds to 1 is not a printable character;
for me the results look like an empty square.
>

Quote:

Originally Posted by

select * from t


>
This returns the one row of the table.
x y
---------------- ----
bob
fred NULL
>

Quote:

Originally Posted by

Please explain me and corect this code.


>
The code is correct, though it looks like a simple example of
something rather than anything of actual use.
>
Roy Harvey
Beacon Falls, CT


Thank You very much.