R2i DotNetNuke® Forum

R2i wants you to have the opportunity to ask questions, post reviews, help others or just rant and rave about DotNetNuke® or any of the R2i Modules and Skins. Our team spends hour upon hour, day after day, working on custom DotNetNuke® modules and services; please feel free to ask us anything.
 
Any way to create a Multi-Column Layout? (Down then Across)
Last Post 10 Mar 2009 08:40 PM by svedire. 4 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Informative
mlarsenUser is Offline
New Member
New Member
Posts:49

--
22 Dec 2006 03:32 PM  
I am trying to create a Multi-Column Layout that displays down then across. I have a header group display then items and after I get half way through the records I would like to start a new column. Any way to do accomplish this?
bgatesUser is Offline
Basic Member
Basic Member
Posts:196

--
27 Dec 2006 03:04 AM  
That would be quite complicated. I know you can do a "SELECT TOP 50 PERCENT ... " for your main query, and that will return the first half of the records. The second half would have to be done using an inner SELECT statement that selects the TOP 50 PERCENT, but the order is reverse (essentially, grab the last 50 percent). The outer SELECT statement would then reverse the order so that it comes out the same. End result: two separate result sets each containing approximately half of the records. So then the problem becomes: how do I get it into a single resultset so that ListX can handle it nicely.

Here are the steps you'll have to do in your main query:
1) Create a temporary table with an identity column (say, RowNumber) and has 2 columns for every column you want displayed. For example, if you're doing a side-by-side listing of the Tabs in your system, then create a temp table with fields: TabID1, TabName1, TabID2, TabName2.
2) Insert into the fields ending with 1 using the statement "SELECT TOP 50 PERCENT ...".
3) Insert into the fields ending with 2 using the reversal statement "SELECT * FROM (SELECT TOP 50 PERCENT FROM... ORDER BY ...)"
4) Update the fields in the first half of the records with data from the second half.
5) Delete the second half of the records.

In your formatting, use the fields TabID1 and TabID2 to show the tab ids side-by-side. The complete SQL is below.


DECLARE @HalfCount int /* This is used for marking the first half of the records */

CREATE TABLE #tmpTabs
(
RowNumber [int] IDENTITY(1,1) NOT NULL,
TabID1 [int],
TabName1 [nvarchar](250),
TabOrder1 [int],
TabID2 [int],
TabName2 [nvarchar](250),
TabOrder2 [int]
)

INSERT INTO #tmpTabs (TabID1, TabName1, TabOrder1)
SELECT TOP 50 PERCENT TabID, TabName, TabOrder
FROM Tabs
ORDER BY TabOrder ASC
SELECT @HalfCount = SCOPE_IDENTITY() /* Retains RowNumber for last record written */

INSERT INTO #tmpTabs (TabID2, TabName2, TabOrder2)
SELECT *
FROM ( /* This is the inner reversed statement */
SELECT TOP 50 PERCENT TabID, TabName, TabOrder
FROM Tabs
ORDER BY TabOrder DESC) ReverseTabs
ORDER BY TabOrder ASC

/* Update the first half of the records with data from the second half */
UPDATE #tmpTabs SET
TabID2 = Half.TabID2,
TabName2 = Half.TabName2,
TabOrder2 = Half.TabOrder2
FROM #tmpTabs INNER JOIN (SELECT (RowNumber - @HalfCount) AS RowNumber, TabID2, TabName2, TabOrder2 FROM #tmpTabs) Half
ON #tmpTabs.RowNumber = Half.RowNumber

/* Remove the extraneous half */
DELETE FROM #tmpTabs WHERE RowNumber > @HalfCount

SELECT * FROM #tmpTabs ORDER BY TabOrder1, TabOrder2


Your format is then simply:
<tr><td>[TabName1]</td><td> | </td><td>[TabName2]</td></tr>
Bob Gates<br>Business Intelligence Force, Inc. (<a href="http://dnn.bi4ce.com"><b>bi4ce</b></a>)
mlarsenUser is Offline
New Member
New Member
Posts:49

--
27 Dec 2006 02:58 PM  
That worked perfectly! Thanks Bob!
mstoyanovichUser is Offline
New Member
New Member
Posts:3

--
05 Oct 2008 08:45 PM  
I'm trying to do the same with ListX as you noted a couple of years ago (slightly different with the following code - I added comments per your original post so you can see what I'm doing - and am getting an error).

First, the SQL...

DECLARE @HalfCount int /* As noted this is used for marking the first half of the records */

CREATE TABLE #tmpSeries
(
RowNumber [int] IDENTITY(1,1) NOT NULL,
SeriesID1 [int],
SeriesDescription1 [nvarchar](250),
SeriesID2 [int],
SeriesDescription2 [nvarchar](250),
)

INSERT INTO #tmpSeries (SeriesID1, SeriesDescription1)
SELECT TOP 50 PERCENT SeriesID, SeriesDescription
FROM Series
WHERE dbo.Series.SeriesID NOT IN (3, 20, 18, 7, 13, 26, 23)
ORDER BY SeriesDescription ASC
SELECT @HalfCount = SCOPE_IDENTITY() /* Retain RowNumber for last record written */

INSERT INTO #tmpSeries (SeriesID2, SeriesDescription2)
SELECT *
FROM ( /* As noted, here is the inner reversed statement */
SELECT TOP 50 PERCENT SeriesID, SeriesDescription
FROM Series
WHERE dbo.Series.SeriesID NOT IN (3, 20, 18, 7, 13, 26, 23)
ORDER BY SeriesDescription DESC) ReverseSeries
ORDER BY SeriesDescription ASC

/* Update the first half of the records with data from the second half */
UPDATE #tmpSeries SET
SeriesID2 = Half.SeriesID2,
SeriesDescription2 = Half.SeriesDescription2,
FROM #tmpSeries INNER JOIN (SELECT (RowNumber - @HalfCount) AS RowNumber, SeriesID2, SeriesDescription2 FROM #tmpSeries) Half
ON #tmpSeries.RowNumber = Half.RowNumber

/* Remove the extraneous half */
DELETE FROM #tmpSeries WHERE RowNumber > @HalfCount

SELECT * FROM #tmpSeries ORDER BY SeriesDescription1, SeriesDescription2

Now the error...
I keep getting an error in the UPDATE statement, specifically in the From record...

Msg 156, Level 15, State 1, Line 32
Incorrect syntax near the keyword 'FROM'.
Msg 102, Level 15, State 1, Line 32
Incorrect syntax near 'Half'.

Anything I'm missing? I've been working on a lot of other things and don't doubt I'm missing something obvious.

I'm using SQL Server 2005...

Thanks in advance.
svedireUser is Offline
Basic Member
Basic Member
Posts:128

--
10 Mar 2009 08:40 PM  
Hi,

Sorry for the late reply.. If you are still getting the same error, then the solution is that you have to remove the extra ,(comma) that you have in the update statement - "SeriesDescription2 = Half.SeriesDescription2, ".

Thanks,
Sindura
R2integrated
You are not authorized to post a reply.

Active Forums 4.1
 

New York, NY • Baltimore, MD • Vienna, VA • St. Louis, MO • Seatle, WA • 410.327.0007 • info@R2Integrated.com

Bookmark & Share Bookmark and Share