Showing posts with label tsql. Show all posts
Showing posts with label tsql. Show all posts

Tuesday, March 20, 2012

a TSQL question

i want to write a query that will return last created 200 records + record
with the minimum ID.
is there a way to do that in one single Select statement?
Following statement should return the record that has the minimum ID too.
SELECT TOP 200 ID , CREATEDATE
FROM TBL_RECORDS
ORDER BY CREATEDATE DESC
ID column has IDENTITY property and There could be records with negative IDs
which come through synchronization.
Thanks in advance..Well, what do you mean by single select? Union would probably be the best
solution here, why dont you use that?
MC
"prefect" <uykusuz@.uykusuz.com> wrote in message
news:uJjpdS$KGHA.2300@.TK2MSFTNGP15.phx.gbl...
>i want to write a query that will return last created 200 records + record
>with the minimum ID.
> is there a way to do that in one single Select statement?
> Following statement should return the record that has the minimum ID too.
> SELECT TOP 200 ID , CREATEDATE
> FROM TBL_RECORDS
> ORDER BY CREATEDATE DESC
> ID column has IDENTITY property and There could be records with negative
> IDs which come through synchronization.
> Thanks in advance..
>|||Thanks for the answers ,

> Well, what do you mean by single select? Union would probably be the best
> solution here, why dont you use that?
that is what i mean with single select! i plan to use this query in a RDA
application. I am
not sure that RDA's Pull method with "tracking on" option supports the
UNION operator.
Anyway , i will give a try with UNION method,i hope it works :)

Thursday, February 16, 2012

A Problem in TSQL

Hi ALL,
I'd like to have a help to the problem.
If I make a SELECT as:
select * from [LS].[msdb].[dbo].[sysfiles]
(hier LS is a linked server) it working fine.
The following lines dont work:
DECLARE @.STR NVARCHAR ( 300 )
SELECT @.STR =3D 'select * from [LS].[msdb].[dbo].[sysfiles]'
EXECUTE @.STR
I get the message:
Server: Nachr.-Nr. 203, Schweregrad 16, Status 2, Zeile 3
Der Name 'SELECT * FROM [LS].[msdb].[dbo].[sysfiles]' ist
kein g=FCltiger Bezeichner.
Whot is wrong?=20
How can I correct it?
Regards
Simon
Hi,
Enclose the varible in parenthesis execute (@.STR)
DECLARE @.STR NVARCHAR ( 300 )
SELECT @.STR = 'select * from [LS].[msdb].[dbo].[sysfiles]'
execute(@.STR)
Or use the below query using sp_executesql
DECLARE @.STR NVARCHAR ( 300 )
SELECT @.STR = 'select * from [LS].[msdb].[dbo].[sysfiles]'
exec sp_executesql @.STR
Thanks
Hari
MCDBA
"Simon" <anonymous@.discussions.microsoft.com> wrote in message
news:2ae0c01c46805$524e12b0$a501280a@.phx.gbl...
Hi ALL,
I'd like to have a help to the problem.
If I make a SELECT as:
select * from [LS].[msdb].[dbo].[sysfiles]
(hier LS is a linked server) it working fine.
The following lines dont work:
DECLARE @.STR NVARCHAR ( 300 )
SELECT @.STR = 'select * from [LS].[msdb].[dbo].[sysfiles]'
EXECUTE @.STR
I get the message:
Server: Nachr.-Nr. 203, Schweregrad 16, Status 2, Zeile 3
Der Name 'SELECT * FROM [LS].[msdb].[dbo].[sysfiles]' ist
kein gltiger Bezeichner.
Whot is wrong?
How can I correct it?
Regards
Simon

A Problem in TSQL

Hi ALL,
I'd like to have a help to the problem.
If I make a SELECT as:
select * from [LS].[msdb].[dbo].[sysfiles]
(hier LS is a linked server) it working fine.
The following lines dont work:
DECLARE @.STR NVARCHAR ( 300 )
SELECT @.STR =3D 'select * from [LS].[msdb].[dbo].[sysfiles]'
EXECUTE @.STR
I get the message:
Server: Nachr.-Nr. 203, Schweregrad 16, Status 2, Zeile 3
Der Name 'SELECT * FROM [LS].[msdb].[dbo].[sysfiles]' ist
kein g=FCltiger Bezeichner.
Whot is wrong?=20
How can I correct it?
Regards
SimonHi,
Enclose the varible in parenthesis execute (@.STR)
DECLARE @.STR NVARCHAR ( 300 )
SELECT @.STR = 'select * from [LS].[msdb].[dbo].[sysfiles]'
execute(@.STR)
Or use the below query using sp_executesql
DECLARE @.STR NVARCHAR ( 300 )
SELECT @.STR = 'select * from [LS].[msdb].[dbo].[sysfiles]'
exec sp_executesql @.STR
Thanks
Hari
MCDBA
"Simon" <anonymous@.discussions.microsoft.com> wrote in message
news:2ae0c01c46805$524e12b0$a501280a@.phx
.gbl...
Hi ALL,
I'd like to have a help to the problem.
If I make a SELECT as:
select * from [LS].[msdb].[dbo].[sysfiles]
(hier LS is a linked server) it working fine.
The following lines dont work:
DECLARE @.STR NVARCHAR ( 300 )
SELECT @.STR = 'select * from [LS].[msdb].[dbo].[sysfiles]'
EXECUTE @.STR
I get the message:
Server: Nachr.-Nr. 203, Schweregrad 16, Status 2, Zeile 3
Der Name 'SELECT * FROM [LS].[msdb].[dbo].[sysfiles]' ist
kein gltiger Bezeichner.
Whot is wrong?
How can I correct it?
Regards
Simon

Saturday, February 11, 2012

A good TSQL editor/debugger

Greetings.
Which is the best tool to use for editing SQL , and debugging SPs?
Must have features are auto-complete of column members and SP parameters and
good query plan/server trace outputs.
Thanks.
Elias.
Hi,
Query Analyzer is the best tool to do all. You could do all the belwo:-
1. Execution plans
2. Set statistics IO ON, SET STATISTICS TIME ON
3. Index tuning
4. Debugging
The list goes on and on...
Thanks
Hari
SQL Server MVP.
"elias448" <elias448@.discussions.microsoft.com> wrote in message
news:E3D4D66B-EDD4-4844-B0F0-37EDD8AEC284@.microsoft.com...
> Greetings.
> Which is the best tool to use for editing SQL , and debugging SPs?
> Must have features are auto-complete of column members and SP parameters
> and
> good query plan/server trace outputs.
> Thanks.
> Elias.
|||Thanks for the reply. I was looking for a tool that has more advanced
editing options, for example, auto-completion of table column names (in
the same way Intellisense works in VB).
|||One possibility is SQL-Programmer from BMC which has
intellisense and a debugger:
http://www.bmc.com/products/products..._0_105,00.html
-Sue
On 7 Jun 2005 05:56:11 -0700, "Liakos"
<elias448@.hotmail.com> wrote:

>Thanks for the reply. I was looking for a tool that has more advanced
>editing options, for example, auto-completion of table column names (in
>the same way Intellisense works in VB).
|||FWIW, yesterday I downloaded and started using ApexSQL Edit.
Can't say I've tested it thoroughly yet, but so far I'm pretty
impressed. It does many of the things you mentioned. Download the
free trial and give it a whirl.
http://www.apexsql.com
Joe Webb
SQL Server MVP
~~~
Get up to speed quickly with SQLNS
http://www.amazon.com/exec/obidos/tg...l/-/0972688811
I support PASS, the Professional Association for SQL Server.
(www.sqlpass.org)
On 7 Jun 2005 05:56:11 -0700, "Liakos" <elias448@.hotmail.com> wrote:

>Thanks for the reply. I was looking for a tool that has more advanced
>editing options, for example, auto-completion of table column names (in
>the same way Intellisense works in VB).
|||You should also check out SQL IDE from Imceda Software (http://www.imceda.com). If you're an Oracle person, TOAD reigns supreme. (TOAD is also in beta for SQL Server at http://www.toadsoft.com/toadssbeta.html.)
Hope this helps,
-Kev
~~~
-Kevin Kline
Quest Software (www.quest.com)
SQL Server MVP
I support PASS, the Professional Association for SQL Server. (www.sqlpass.org)

> Thanks for the reply. I was looking for a tool that has more advanced
> editing options, for example, auto-completion of table column names
> (in the same way Intellisense works in VB).
>
|||Or give http://www.agileinfollc.com DataStudio a try for table editing.
John King
http://www.agileinfollc.com
"Kevin Kline [MVP]" <kevin.kline[NOSPAM]@.quest.com> wrote in message
news:uQqMjlEfFHA.3304@.TK2MSFTNGP12.phx.gbl...
> You should also check out SQL IDE from Imceda Software
> (http://www.imceda.com). If you're an Oracle person, TOAD reigns supreme.
> (TOAD is also in beta for SQL Server at
> http://www.toadsoft.com/toadssbeta.html.)
> Hope this helps,
> -Kev
> ~~~
> -Kevin Kline
> Quest Software (www.quest.com)
> SQL Server MVP
> I support PASS, the Professional Association for SQL Server.
> (www.sqlpass.org)
>