Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

« Newer Snippets
Older Snippets »
5 total  XML / RSS feed 

SQL Update with Values from Second Table

// Update multiple fields in a table based on values in a second table. This prevents you from having to use multiple sub-queries.

UPDATE table
SET col1 = a.col1, col2=a.col2
FROM anotherTable a
WHERE a.anotherTableID = 1

Scripting schema updates in MSSQL #1

This SQL statement will alter a table only if a column in the table to be altered does NOT contain a column named 'FavoriteColorId'.

From: http://haacked.com/

IF NOT EXISTS
(
    SELECT * FROM [information_schema].[columns]
    WHERE    table_name   = 'Customer'
    AND      table_schema = 'dbo'
    AND      column_name  = 'FavoriteColorId'
)
BEGIN
    ALTER TABLE [dbo].[Customer]
    ADD FavoriteColorId int

How to update something using a patch (Wordpress, pmwiki etc.)

After unzipping, taring or whatever archive you used copy thepatch over the old files, replacing them.

Copy the files in your newly extracted directory (pmwik-new/wordpress-patch) over the files of your existing software installation. For example, if your existing PmWiki/Wordpress installation is in a directory called pmwiki/wordpress, then one way to copy the new files over the existing ones is to enter the command:
cp -a pmwiki-new/. pmwiki


Note that BSD systems will not have the -a option as a command-line argument for cp, but that's okay, since it's just shorthand for cp -dpR, so use that instead of -a.

On (some) FreeBSD servers and Mac OS X systems you need to use
cp -Rpv pmwiki-new/. pmwiki 

This works well on TxD shared hosting.

Update From sample

// sample "update from" sql statement

UPDATE 
        [Crm].[tbPartyLegalEntityData]
SET 
        [CompanyType] = ape.[CompanyType],
        [EmployeesCount] = ape.[EmployeesCount]
FROM 
        [Crm].[tbPartyLegalEntityData] p
INNER JOIN 
        App.[tbApplicationPersonEmployer] AS ape 
ON 
        ape.[Bulstat] = p.[Bulstat]
WHERE 
        ape.[Bulstat] <> '!' 
        AND [ape].[EmployeesCount] IS NOT NULL 
        AND [ape].[CompanyType] IS NOT NULL

count duplicate users and store in db - sql

// count duplicate users and store in db

// count users with filter
select Count(surname+firstname) as duplicates, surname, firstname
from c_contact
where show_record=1
group by surname, firstname
having Count(surname+firstname) > 1
order by duplicates, surname, firstname

// original code
SELECT column,COUNT(*) c 
FROM table
GROUP BY column 
HAVING COUNT(*) > 1

//update code
update c_contact
set duplicates = dbo.func_get_duplicates(surname, firstname)
« Newer Snippets
Older Snippets »
5 total  XML / RSS feed