|
Posted by Marko on 12/14/06 10:01
Erland Sommarskog schreef:
> Marko (nortel@planet.nl) writes:
> > It's a column value in a row, the query I run:
> >
> > SELECT @Registernum=(
> > SELECT regnr FROM dbo.planningview
> > WHERE convert(CHAR(11),date ,106) =
> > convert(CHAR(11),GETDATE(),106)
> > AND
> > convert(CHAR(8),Starttime ,108) <=
> > convert(CHAR(8),GETDATE(),108)
> > AND
> > convert(CHAR(8),Stoptime ,108) >=
> > convert(CHAR(8),GETDATE(),108) AND
> >
> > groupName = 'Application' AND shortname = 'Helpdesk' AND
> > deleted =0
> > )
> >
> > if (@Registernum is null) Select @Registernum=0
> > select @Registernum
> > GO
> >
> >
> > What I get is 401234567 instaed of 0401234567, so I am missing the 0
> > (zero).
>
> You failed to include the declaration of @Registernum. I would guess
> you have declared it as integer or decimal.
>
> Also, write conditions like
>
> WHERE convert(CHAR(11),date ,106) = convert(CHAR(11),GETDATE(),106)
>
> as
>
> WHERE date >= convert(char(8), getdate(), 112)
> AND date < convert(char(8), dateadd(DAY, getdate() + 1), 112)
>
> This can be essential for performance. If the date column is indexed,
> the index is no of use if you put the column into an expression.
>
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se
>
>
Hello Erland,
I put the DECLARE above the Query:
DECLARE @Registernum integer
but no results, I got still the value without the zero (0).
The Data Type of the Column is CHAR, is this maybe wrong?
Navigation:
[Reply to this message]
|