Showing posts with label editor. Show all posts
Showing posts with label editor. Show all posts

Monday, March 12, 2012

Query Editor: how to display individual row vertically

In query editor I displayed a single row from a table. The row is so long that I need to scroll horizontally back and forth to check out it's fields. Using t-sql (or otherwise) can I display the row like this: (vertically)

\

Field Name 1: < data value 1>

Field Name 2: < data value 2>

Field Name 3: < data value 3>

Field Name 4: < data value 4>

etc.

TIA,

barkingdog

Dog:

If you are using SQL Server 2005, you ought to be able to use an UNPIVOT


Dave

|||

Dog:

That SQL 2005 code might look something like this:

-- -
-- In order for UNPIVOT to work, the data must be homogeneous.
-- For this reason, all of the fields are transformed into a
-- varchar (40) string.
--
-- Also note the ISNULL function on field 3. If this is not
-- done, this row will not be displayed.
-- -
select convert (varchar (25), FieldName + ':') as FieldName,
FieldValue
from ( select convert (varchar (40), 'This is a test.')
as [Field Name 1],
convert (varchar (40), 'This is the 2nd field.')
as [Field Name 2],
convert (varchar (40), isnull (null, '[Null]'))
as [Field Name 3],
convert (varchar (40), 45.27)
as [Field Name 4]
) x
unpivot (FieldValue for FieldName
in ( [Field Name 1], [Field Name 2],
[Field Name 3], [Field Name 4]
)
) as xx

--
-- Sample Output:
--


-- FieldName FieldValue
-- - -
-- Field Name 1: This is a test.
-- Field Name 2: This is the 2nd field.
-- Field Name 3: [Null]
-- Field Name 4: 45.27

-- (4 row(s) affected)

|||

If you are using SQL 2000 you might try something like:

select 'Field Name 1:' as FieldName,
'This is a test.' as fieldValue
union all
select 'Field Name 2:',
'This is the 2nd field.'
union all
select '...', ' '
union all
select 'Field Name N: ', 'Nth piece of data'


--
-- Sample Output:
--


-- FieldName fieldValue
-- -
-- Field Name 1: This is a test.
-- Field Name 2: This is the 2nd field.
-- ...
-- Field Name N: Nth piece of data

-- (4 row(s) affected)

Query Editor standalone? Like Query analyzer

With Sql Server 2000 you could select and launch the query analyzer without going through the Enterprise Manager. Is there a method for doing the same thing with the new Query Editor, without going through the SqlServer Studio Manager?

Thanks;
Mark E. JohnsonBig SmileThere is not, no.|||Mark,

Query Analyzer from SQL Server 2000 can connect to a SQL Server 2005 database and be used as before (Note that I can't give any advice on what licensing issues there may be). Not all of the Object Browser functionality works, but from your question, I suspect that's not as important. But the editor features, including graphical query plans, for example, work just fine against 2005.

Steve Kass
Drew University
SQL Server MVP
|||Thank you. What it really means for us, is that there will be a different method for pulling up the query tool. A discussion about what tools we really desire on a developers desktop etc will be in order.

Thanks again;
Smile