Tuesday, December 8, 2009

the query did it

Creating a query tu update a field in a new table with the same data to be filled in with.

--== the query who did the miracle
select 'update operator set operation = %' + Operation+'%', 'where id = ',' ' +id+'','%' from mySourceDataBase.dbo.Operator

--== the result

update operator set operation = '{0}.Contains("{1}")' where id = 1
update operator set operation = '{0}.NotContains("{1}")' where id = 2
update operator set operation = '{0}.StartsWith("{1}")' where id = 3
update operator set operation = '{0}.EndsWith("{1}")' where id = 4
update operator set operation = '{0} == "{1}"' where id = 5
update operator set operation = '{0} != "{1}"' where id = 6
update operator set operation = '{0} > "{1}"' where id = 7
update operator set operation = '{0} < "{1}"' where id = 8
update operator set operation = '{0} >= "{1}"' where id = 9
update operator set operation = '{0} <= "{1}"' where id = 10
update operator set operation = '{0} == ""' where id = 12
update operator set operation = '{0} != ""' where id = 13
update operator set operation = '{0} == {1}' where id = 18
update operator set operation = '{0} != {1}' where id = 19
update operator set operation = '{0} > {1}' where id = 20
update operator set operation = '{0} < {1}' where id = 21
update operator set operation = '{0} >= {1}' where id = 22
update operator set operation = '{0} <= {1}' where id = 23
update operator set operation = '{0} == DateTime.Parse("{1}")' where id = 31
update operator set operation = '{0} != DateTime.Parse("{1}")' where id = 32
update operator set operation = '{0} > DateTime.Parse("{1}")' where id = 33
update operator set operation = '{0} 'fickler' where id = 34
update operator set operation = '{0} >= DateTime.Parse("{1}")' where id = 35
update operator set operation = '{0} <= DateTime.Parse("{1}")' where id = 36
update operator set operation = '{0} = {1}' where id = 57
update operator set operation = '{0} <> {1}' where id = 58


Monday, December 7, 2009

few sql tips




How to count instances of character in SQL Column

I have an sql column that is a string of 100 Y or Ns eg 'YYNYNYYNNNYYNY...'

What is the easiest way to get the number of Ys in each row


tsql

SELECT LEN(REPLACE(myColumn, 'N', '')) FROM ...

SELECT
LEN(REPLACE(ColumnName, 'N', '')) as NumberOfYs
FROM
SomeTable



2. Trouble inserting data

INSERT INTO DestinationTable
(ColumnA, ColumnB, ColumnC, etc.)
SELECT FROM SourceTable
(ColumnA, ColumnB, ColumnC, etc.)

And my source table has 22 million rows.

SQL server fills up my hard drive, and errors out.

Why can't SQL server handle my query?

Should I use a cursor and insert a row at a time?

the solution

INSERT INTO DestinationTable
(ColumnA, ColumnB, ColumnC, etc.)
SELECT TOP 100000 ColumnA, ColumnB, ColumnC, etc.
FROM SourceTable
WHERE NOT EXISTS (SELECT *
FROM DestinationTable
WHERE DestinationTable.KeyCols = SourceTable.KeyCols)

WHILE @@ROWCOUNT <> 0
INSERT INTO DestinationTable
(ColumnA, ColumnB, ColumnC, etc.)
SELECT TOP 100000 ColumnA, ColumnB, ColumnC, etc.
FROM SourceTable
WHERE NOT EXISTS (SELECT *
FROM DestinationTable
WHERE DestinationTable.KeyCols = SourceTable.KeyCols)

Thursday, December 3, 2009

javascript quick short ones

Getting the elements by Id

var btn = document.getElementById(btnName);
if (btn) btn.click();

Tuesday, December 1, 2009

Xtreme Programming

I found a list of small details on Extreme programming the current methodology used by the company Im working on.
I took some list since I want to check it out through my blog instead of a link. heres the link


Extreme Programming
Extreme Programming (XP) is a lightweight process
Ground rules:
  • small team (2 to 12)
  • continuous access to customers
  • OO design and code (Smalltalk, Java)
  • change management system (code and tests)
  • the system is always “working” (growing functionality over time)
  • overall development cycle – between 4 and 12 months
  • new release to customer every 2-3 months
  • internal iterations every two weeks
  • not for life-critical systems (heart monitor, nuclear power plant, avionics systems, etc.)

Some Rules of Extreme Programming

Planning rules
  • do project planning via “user stories”
  • plan a series of very small internal releases
  • start each day with a “stand-up meeting”
Design rules
  • keep the design simple (use the simplest thing that could work)
  • refactor as needed
Coding rules
  • talk with the customer throughout the coding process
  • always code in pairs
  • code unit tests first
  • follow coding standards
Testing rules
  • unit tests for all code
  • acceptance tests for each user story

Information on XP

Books:
  • Extreme Programming Explained (Kent Beck)
  • Planning Extreme Programming (Beck and Fowler)
  • Questioning Extreme Programming (McBreen)
Web sites:

A day in the life of an XP developer

First thing in the morning: developer attends a stand-up meeting with the rest of the team (10-15 min)
  • developer chooses a task (part of a user story); chooses a development partner for the day
Developer and partner sit together and do the development work for the task
  • write new unit tests, check them into the change management system
  • write new code, check it in
  • fix things that need to be changed in existing code; rerun the unit tests
  • run the new unit tests; run the acceptance tests for the user story
Developer goes home at 5:00 (no overtime)

Planning an XP project

User Stories
  • Capture requirements “in the users’ words”
  • Small, discrete, testable
  • Include scenarios
  • May include business interactions outside system
“Planning Game”
  • Users own stories
  • Developers set and own estimates
  • Users set priorities – “business value”
  • Joint goal: group stories into iterations
  • Business value
  • “Worst first”

Planning an XP project

  • Interview the customer; write user stories on index cards
  • Developers give development estimates for each story
    • estimates in “ideal person-days”
    • estimates based on experience with similar problems
  • If a story is too big, split it into smaller stories
  • Create a release plan – list the stories in each release
    • highest priority or “risky” items early
  • Track execution of the plan
    • Post the user stories on a bulletin board (in time order)
    • Check off each user story after the code is complete and the acceptance tests have passed

Examples of User Stories

see http://www.c2.com/cgi/wiki?UserStoryExamples

Pair Programming

One important practice in XP: all code is reviewed as it is written
  • how does pair programming work?
    • two developers, one workstation
    • one person is the driver, the other is the navigator
    • the navigator suggests design alternatives, checks for conformance to coding standards, prevents driver from writing unreadable code
    • pair assignments usually change every day
  • reduces the need for elaborate design documentation
  • pair programming actually improves productivity

Agile characteristics

Most of the agile processes are “controlled chaos”:
  • short development iterations, with product “shipped” to either a customer or a pseudo-customer at regular intervals
  • continuous testing – such as daily regression tests
  • collecting customer requirements using scenarios or use cases
  • small team sizes
  • informal modeling techniques – CRC cards, simple drawings on whiteboards
  • adaptive planning techniques – plans are updated based on intermediate results and reprioritization by the customers

Agile versus XP

Most agile process are less radical than XP:
  • don’t require pair programming
  • multiple roles, not just “general-purpose developer”
  • various methods of iteration planning
  • existing heavyweight processes can be adapted to be more “agile”

Which agile process?

Scrum
  • Scrum is a very general iteration management process, which can be used in conjunction with any methodology
  • development activities are in 30-day “sprints”
Adapt existing processesCrystal Clear
  • much lighter than XP, but the team must define their own “required project documentation”
  • see Agile Modeling by Scott Ambler for ideas
  • good for a team of 4 to 6 people

Books on Agile Processes

  • Crystal Clear: Writing Effective Use Cases (Cockburn)
  • Scrum: Agile Software Development With Scrum (Schwaber and Beedle)
  • Adaptive Software Development: Adaptive Software Development (Highsmith)
  • DSDM: DSDM, Dynamic Systems Development Method: The Method in Practice (Stapleton)
  • Lean Development: Lean Development: A Toolkit for Software Development Managers (Poppendieck)



by David Laurance / Dennis Mancl