Hierarchical table sorting with a parent-child relationship

This code snippet works beautifully. Just replace the table/field names like so: 

  • AccountID with ID of your child record
  • name with name of your child record
  • parentID with the parent ID of of your child record
  • @tbl_accounts with the name of your hierarchical table

Run and done:

with cte as
(
select
    Accountid,
    name,
    parentid,
    cast(row_number()over(partition by parentid order by name) as varchar(max)) as [path]
from @tbl_accounts
where parentid = 0
union all
select
    t.AccountID,
    t.name,
    t.ParentID,
    [path] + cast(row_number()over(partition by t.parentid order by t.name) as varchar(max))
from
30.    cte
join @tbl_accounts t on cte.AccountID = t.ParentID
)
 
select 
    Accountid,
    name,
    ParentID,
    [path]
from cte
order by path

 

Thanks, Kev Riley!

http://ask.sqlservercentral.com/questions/48518/hierarchical-table-sorting-with-a-parent-child-rel.html

Chart Templates in Excel

Excel Chart Template Button

This technique came in super-handy today:

Reuse a favorite chart by using a chart template in Excel:

http://office.microsoft.com/en-us/excel-help/reuse-a-favorite-chart-by-using-a-chart-template-HA010007205.aspx

I had to make a load of pie charts, but the colors and format were not one of the defaults. It would’ve been painful to have to go through each chart, changing the colors and removing the labels, and moving the title to the top, etc. Instead, I made a chart template and it did all the work for me. 🙂

 

Apply excel formula to entire column – without dragging the mouse

http://answers.yahoo.com/question/index?qid=20080804112727AA9LUBh

copy your formula. Then go to a column that has figures all the way down all […] rows, press <End><Down>. This will shoot you all the way to the very bottom of that column. Now move back over to the column where your formula is. Hold down your <Shift> key, press <End><Up>. This will shoot you all the way back up to your original formula, and because you held down the <Shift> key, it will highlight all […] rows. Now press <Enter>. Voila!

Refreshers of the Day #sql #excel #word

Updating a column to null in SQL

http://publib.boulder.ibm.com/infocenter/idshelp/v10/index.jsp?topic=/com.ibm.sqls.doc/sqls872.htm

Updating columns in general

http://www.w3schools.com/sql/sql_update.asp

Deleting rows in general

http://www.w3schools.com/sql/sql_delete.asp

Copying visible cells only from a filtered excel sheet

http://office.microsoft.com/en-us/excel-help/copy-visible-cells-only-HA010244…

Find and Replace Carriage Returns

http://uk.answers.yahoo.com/question/index?qid=20070929072105AAjHDWu