Wednesday, May 1, 2013

SQL, update a field by the order of another field in the table

This is how I reordered some form elements alphabetically who are shown in order by an ElementOrder field.

Basically I updated a field by the order of another field in the table.

First make a new temporary table with a new identity that will be the new ElementOrder field values and the identity of the rows you're updating

DECLARE @new_table TABLE
(
FormElementID INT not null,
ElementOrder INT not null IDENTITY(82700,100) /*seed, increment, in my case my ElementOrder fields started at 82700 and incremented by 100*/
)
INSERT INTO @new_table
(
FormElementID
)
SELECT FormElementID
FROM FormElements f
WHERE /*narrow down fields here, within a certain section perhaps?*/
ORDER BY /*choose new order, perhaps by name*/

/*Check to make sure your table looks right*/
SELECT * FROM @new_table

Then update the ElementOrder field with the new values from your temporary table

UPDATE FormElements
SET
ElementOrder = (SELECT ElementOrder
FROM @new_table
WHERE FormElementID = FormElements.FormElementID)
WHERE
EXISTS (
SELECT *
FROM @new_table
WHERE FormElementID = FormElements.FormElementID
)

Hope this works for you :)

Tuesday, April 30, 2013

Need to generate a GUID?

Need to generate a GUID? I use this thing all the time, might as well give a shout out :)  

http://www.guidgenerator.com/online-guid-generator.aspx

 

Saturday, April 13, 2013

Driving home

It's kinda a pretty ride.









Breakfast faves





Friday, March 29, 2013

Super Hero Love!

Clark Kent
Peter Parker
James Logan
Tony Stark
Steve Trevor
Bruce Banner
Donald Blake
Bruce Wayne

Louis Lane
Mary Jane
Jean Grey
Pepper Potts
Diana Prince
Betty Ross
Jane Foster
Dick Grayson