Mac OSX – Stop OS X apache service and prevent automatic running (OS X SERVER)

I already run MAMP as a local server environment for apache and MySQL, so when I installed Mac OS X Server, which runs it’s own instance of apache, my server encountered problems with MAMP which failed to start.

After some investigation I found the OS X Server instance of Apache started with the system resulting in MAMP failing to start, with no obvious setting to disable the in-built apache services in the OS X Server app settings.

Here’s how to prevent the service starting automatically, then kill the existing service:

Step 1: Locate the following file: /Library/Server/Web/Config/Proxy/apache_serviceproxy.conf

Step 2: Comment out the listening ports in the file

Example using standard ports, change:
Listen 80
Listen 443

To:
# Listen 80
# Listen 443

This prevents apache from starting.

Step 3: Stop inbuilt apache server. Open Terminal, type: sudo killall httpd

Type the following to check http instance have stopped: ps -Al | grep httpd

Inbuilt apache service should now stop and won’t re-start.

SQL – How to Update and Select in the same query

The OUTPUT clause Returns information on each row affected by an INSERT, UPDATE, DELETE, or MERGE statement.

These results can be returned to the processing application for further use.

The following example uses the OUTPUT clause to return row values in conjunction with an UPDATE query which effectively enables a SELECT and UPDATE command in the same query.
 
— CREATE TEMP TABLE
CREATE TABLE #TempTable ( URN INT, F1 VARCHAR( 50), F2 VARCHAR(50 ), USED VARCHAR (1))
— INSERT DATA
insert into #TempTable values ( 1,’F1_Val_1′ ,’F2_val_1′, ‘N’)
insert into #TempTable values ( 2,’F1_Val_2′ ,’F2_val_2′, ‘N’)
insert into #TempTable values ( 3,’F1_Val_3′ ,’F2_val_3′, ‘N’)

— UPDATE SINGLE ROW IN TABLE WITH NEW VALUE
— USING OUTPUT COMMAND TO RETURN FIELDS OF UPDATED ROW
UPDATE #TempTable
SET F1 = ‘F1_New_Val’
OUTPUT Inserted.URN, Inserted.F1, Inserted.F2
WHERE URN = 1

— UPDATE MULTIPLE ROWS IN TABLE WITH NEW VALUE
— USING OUTPUT COMMAND TO RETURN FIELDS OF UPDATED ROWS
UPDATE #TempTable
SET F1 = ‘F1_And_F3_new_Val’
OUTPUT Inserted.URN, Inserted.F1, Inserted.F2
WHERE URN in (1 ,3)

— UPDATE ALL ROWS IN TABLE WITH NEW VALUE
— USING OUTPUT COMMAND TO RETURN FIELDS OF ALL ROWS IN TABLE
UPDATE #TempTable
SET F1 = ‘New_Global_Val’
OUTPUT Inserted.URN, Inserted.F1, Inserted.F2

— UPDATE TOP 1 ROW IN TABLE WITH NEW VALUE
— MARK USED = ‘Y’
— USING OUTPUT COMMAND TO RETURN FIELDS OF UPDATED ROW
UPDATE #TempTable
SET F1   = ‘F1_New_Val’
,USED = ‘Y’
OUTPUT Inserted.URN, Inserted.F1, Inserted.F2
WHERE URN in (select max( URN) from #TempTable WHERE used = ‘N’)

— DROP TEMP TABLE
DROP TABLE #TempTable

 

SQL – How to list the files in a directory

Here is a simple script that reads the file names from a specified directory.
The results are held in a table that can be referenced, and then dropped when the script has completed.

declare @DIR as varchar(100)
set @DIR = ‘dir c:\’ — ENTER DIRECTORY PATH HERE 

use ORDERS
create table files_TMP (filenames varchar(max)) 

insert into files_TMP
exec master..xp_cmdshell @DIR 

select * from files_TMP
 
drop
table files_TMP