September 17, 2010 at 1:30 am
Select top 5 'MY DATABASE TABLE: ' + name from sysobjects where xtype = 'u'
order by 1 desc
Present output:
MY DATABASE TABLE: WEBEX_MEETING_PRODUCT_ATTENDEE
MY DATABASE TABLE: WEBEX_ACCOUNT_CONFIG
MY DATABASE TABLE: VENDOR
MY DATABASE TABLE: USER_REQUEST
MY DATABASE TABLE: USER_GROUP
required output:
MY DATABASE TABLE :
LU_SFORCE_MULTIPLE_MATCH_ACTION_TYPE
LU_LAST_OPT_OUT_BY
LU_CHART_TYPE
LU_AGENDA_ITEM_CATEGORY
ACCOUNT_ROOMMATE_EMAIL
but i DONT want to use UNION here like select 'MY DATABASE TABLE : ' union
Select top 5 name from sysobjects where xtype = 'u'
order by 1 desc
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
September 17, 2010 at 2:56 am
How come you don't want to use UNION? It is possible to write a query that does this as a set without UNION but it is very contorted.
Is a variable ok?
DECLARE@string AS NVARCHAR(MAX)
SELECT TOP 5
@string = COALESCE(@string, N'MY DATABASE TABLE: ') + CHAR(10) + name
FROM sys.tables
ORDER BY
name DESC
SELECT @string
September 17, 2010 at 3:00 am
And here it is. Nasty, eh?
SELECT TOP 6
the_output = CASE
WHEN tables.name = yucky.first_table THEN
N'MY DATABASE TABLE: '
ELSE
name
END
FROM sys.tables
CROSS JOIN
(
SELECT first_table = MIN(name)
FROM sys.tables
) AS yucky
ORDER BY
CASE
WHEN tables.name = yucky.first_table THEN
CHAR(255)
ELSE
name
END DESC
September 17, 2010 at 3:45 am
How about an outer join from a tally table (where row = required number of rows+1) to a cte which has a rownumber function.
The you simply need to isnull the non-joined tally table row.
September 17, 2010 at 7:22 am
Probably not what you're looking for, but how's this?
Select top 5 'MY DATABASE TABLE: ' = name
from sysobjects
where xtype = 'u'
order by 1 desc
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
September 19, 2010 at 10:46 pm
WayneS (9/17/2010)
Probably not what you're looking for, but how's this?
Select top 5 'MY DATABASE TABLE: ' = name
from sysobjects
where xtype = 'u'
order by 1 desc
Thanks wayne but i posted it in my first post 🙂
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
September 19, 2010 at 11:15 pm
Bhuvnesh (9/19/2010)
WayneS (9/17/2010)
Probably not what you're looking for, but how's this?
Select top 5 'MY DATABASE TABLE: ' = name
from sysobjects
where xtype = 'u'
order by 1 desc
Thanks wayne but i posted it in my first post 🙂
Ummm.... Nope... you didn't. Look again... a bit more carefully this time. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
September 19, 2010 at 11:24 pm
Jeff Moden (9/19/2010)
Bhuvnesh (9/19/2010)
WayneS (9/17/2010)
Probably not what you're looking for, but how's this?
Select top 5 'MY DATABASE TABLE: ' = name
from sysobjects
where xtype = 'u'
order by 1 desc
Thanks wayne but i posted it in my first post 🙂
Ummm.... Nope... you didn't. Look again... a bit more carefully this time. 😉
oohhh .PERFECT solution from wayne ( 90$ to wayne and 10$ for jeff)
-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply