Blog Home 
Scott Yokiel MOSS 2007 & .NET blog (and some bad spelling) - Thursday, March 20, 2008

RSS 2.0 Atom 1.0 CDF  
 
Sign In
 
 Thursday, March 20, 2008

 

Here is a simple example of a pivot function in SQL 2005

 

CREATE TABLE #UserTime

(

UserName VARCHAR(50),

Class VARCHAR(50),

Week_Date DATETIME,

Hours DECIMAL(5,2),

CategoryName VARCHAR(50),

IsBillable BIT,

CategoryAppr VARCHAR(5)

)

INSERT INTO #UserTime SELECT 'SYOKIEL','MPLS','2008-02-17',40,'Client Billable', 1,'CB'

INSERT INTO #UserTime SELECT 'SYOKIEL','MPLS','2008-02-24',16.00 ,'Administration' , 0,'AD'

INSERT INTO #UserTime SELECT 'SYOKIEL','MPLS','2008-02-24',3.00,'Client Billable' ,1,'CB'

INSERT INTO #UserTime SELECT 'SYOKIEL','MPLS','2008-02-24',21.00,'PTO' ,0,'PTO'

INSERT INTO #UserTime SELECT 'SYOKIEL','MPLS','2008-03-02',40.00,'Client Billable' ,1,'CB'

INSERT INTO #UserTime SELECT 'SYOKIEL','MPLS','2008-03-09',36.00 ,'Client Billable',1,'CB'

INSERT INTO #UserTime SELECT 'SYOKIEL','MPLS','2008-03-09',4.00 ,'PTO',0,'PTO'

Select * from #UserTime

--SELECT Final.UserName,Final.Week_Date, SUM(Final.CB) ,SUM(Final.AD),SUM(Final.PTO)

--from

--(SELECT UserName,Week_Date, [CB] as CB, [AD] as AD, [PTO] as PTO

-- FROM #UserTime AS P

-- PIVOT

-- (

-- Sum(P.Hours)

-- FOR P.CategoryAppr

-- IN([CB], [AD], [PTO])

-- ) AS Pivoted

--) as Final

--Group By Final.UserName,Final.Week_Date

SELECT UserName, Week_Date, SUM([0]) as NonBillable, SUM([1]) as Billable

FROM #UserTime AS P

PIVOT

(Sum(P.Hours)

FOR P.IsBillable

IN([0], [1])

) AS Pivoted

Group By UserName, Week_Date

DROP TABLE #UserTime

3/20/2008 3:01:59 PM (Central Standard Time, UTC-06:00)  #    Comments [0]    |  Trackback
 Tuesday, January 22, 2008
Heres's a simple way to pass in a xml chunk that you can easiy put int  atemp table to join to.

DECLARE @X xml
SET @X = '<root><value id=''12196825'' /></root>'

SELECT List.c.value('.','int')
FROM @X.nodes('/root/value/@id') List(c)

1/22/2008 10:04:15 AM (Central Standard Time, UTC-06:00)  #    Comments [0]    |  Trackback
 Friday, January 04, 2008
I wrote a simple page to test my database on a remote server.  Since i can't connect remotly this little page lets me run sql commands via a web browser and tst the conn string.

TestDB.zip (2.46 KB)
1/4/2008 9:46:48 AM (Central Standard Time, UTC-06:00)  #    Comments [0]    |  Trackback
 Tuesday, November 13, 2007
I thought this would be useful in the future so i'm adding it...

DECLARE @LoadList as VARCHAR(MAX)
SET @LoadList = '9681549,9681554'

CREATE TABLE #LoadNumbers
(
    LoadNum int
)

DECLARE @LoadNum varchar(10), @Pos int

SET @LoadList = LTRIM(RTRIM(@LoadList))+ ','
SET @Pos = CHARINDEX(',', @LoadList, 1)

IF REPLACE(@LoadList, ',', '') <> ''
BEGIN
    WHILE @Pos > 0
    BEGIN
        SET @LoadNum = LTRIM(RTRIM(LEFT(@LoadList, @Pos - 1)))
        IF @LoadNum <> ''
        BEGIN
            INSERT INTO #LoadNumbers (LoadNum) VALUES (CAST(@LoadNum AS int)) --Use Appropriate conversion
        END
        SET @LoadList = RIGHT(@LoadList, LEN(@LoadList) - @Pos)
        SET @Pos = CHARINDEX(',', @LoadList, 1)

    END
END

SELECT * FROM #LoadNumbers

DROP TABLE #LoadNumbers

11/13/2007 9:16:20 AM (Central Standard Time, UTC-06:00)  #    Comments [0]    |  Trackback
 Saturday, October 27, 2007

So i just finished my code camp presentation and wanted to post my slide deck and any code i used to show how to start creating sharepoint webparts.  I did a little embedded web site demo, a classic web part demo and also showed a bit of smart part.  There should also be a rough script of how to go about each of these.  If you have any question please feel free to drop me an email.  Have a good one.

scott

 

Wheres the code you say?  Sorry forgot to press that silly upload button... here it is

 

Fall2007CodeCamp.zip (1.45 MB)
10/27/2007 9:43:31 AM (Central Standard Time, UTC-06:00)  #    Comments [1]    |  Trackback
Copyright © 2008 RBA Consulting.