How would i add order by to this syntax below:
"Select * Into ETCLog_holding from etclog where box# BETWEEN " & Box1 &
" and " & Box2
i have tried adding it to the end after box2 but its doesnt work.
Any ideas?How did you try "adding it to the end"? Were you careful to add a SPACE?
& Box2 & " ORDER BY ..."
--^ important!
Is your column really named box#? Ugh.
<pkruti@.hotmail.com> wrote in message
news:1140540628.486260.116830@.f14g2000cwb.googlegroups.com...
> How would i add order by to this syntax below:
> "Select * Into ETCLog_holding from etclog where box# BETWEEN " & Box1 &
> " and " & Box2
> i have tried adding it to the end after box2 but its doesnt work.
> Any ideas?
>|||pkr...@.hotmail.com wrote:
> How would i add order by to this syntax below:
> "Select * Into ETCLog_holding from etclog where box# BETWEEN " & Box1 &
> " and " & Box2
> i have tried adding it to the end after box2 but its doesnt work.
> Any ideas?
What are "Box1" and "Box2"? Is this code taken from your
user-interface? Never concatenate unverified input from users like
that. It's dangerously insecure as well as inefficient. The best way is
to pass a pair of a parameters to a SQL stored procedure:
CREATE PROC usp_foo
(@.box1 INTEGER, @.box2 INTEGER)
SELECT
..
WHERE [box#] BETWEEN @.box1 AND @.box2
GO
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Aaron Bertrand [SQL Server MVP] wrote:
> How did you try "adding it to the end"? Were you careful to add a SPACE?
> & Box2 & " ORDER BY ..."
> --^ important!
> Is your column really named box#? Ugh.
>
> <pkruti@.hotmail.com> wrote in message
> news:1140540628.486260.116830@.f14g2000cwb.googlegroups.com...
SELECT INTO creates a table and tables are unordered. For that reason
the ORDER BY may be ignored. Don't use ORDER BY here because it doesn't
achieve anything useful that you can rely on.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--|||Did you tried this?
"Select * Into ETCLog_holding from etclog where box# BETWEEN " & Box1 & "
and " & Box2 & " order by [column from etclog]"
"pkruti@.hotmail.com" wrote:
> How would i add order by to this syntax below:
> "Select * Into ETCLog_holding from etclog where box# BETWEEN " & Box1 &
> " and " & Box2
> i have tried adding it to the end after box2 but its doesnt work.
> Any ideas?
>|||> SELECT INTO creates a table and tables are unordered. For that reason
> the ORDER BY may be ignored. Don't use ORDER BY here because it doesn't
> achieve anything useful that you can rely on.
I was just trying to point out a potential correction the syntax (especially
given we have no idea what "doesnt work" means). The query in querstion
might very well be used for other purposes than SELECT INTO.|||Aaron Bertrand [SQL Server MVP] wrote:
> I was just trying to point out a potential correction the syntax (especial
ly
> given we have no idea what "doesnt work" means). The query in querstion
> might very well be used for other purposes than SELECT INTO.
Aaron,
I knew that you knew. I didn't know if the OP knew. I don't know what
"doesn't work" means either.
David Portas, SQL Server MVP
Whenever possible please post enough code to reproduce your problem.
Including CREATE TABLE and INSERT statements usually helps.
State what version of SQL Server you are using and specify the content
of any error messages.
SQL Server Books Online:
http://msdn2.microsoft.com/library/ms130214(en-US,SQL.90).aspx
--
No comments:
Post a Comment