Badges

Types

Formats

Show Only

SMTP from MSSQL Procedure
https://mreschke.com/167/smtp-from-mssql-procedure
Ability to send an email from a MSSQL Stored Procedure http:www.sqldev.net/xp/xpsmtp.htm Download the attached .zip and extract Copy the xpsmtp80.dll to C:\Program Files\Microsoft SQL Server\MSSQL\Binn Run this procedure on the servers master database _ exec sp_addextendedproc 'xp_smtp_sendmail', 'xpsmtp80.dll' Use this syntax for a simple email _ DECLARE @rc INT EXEC @rc = master.dbo.xp_smtp_sendmail @FROM = N'from@email.com', @FROM_NAME = N'fromname', @replyto = N'replyto@email.com', @TO = N'...
|
post #167 by mreschke Dec 23rd 2009 (6579 views)
Display Table Sizes in MSSQL
https://mreschke.com/147/display-table-sizes-in-mssql
This query will display a list of all tables along with disk sizes and index sizes -- Get all tables rows count, sizes, index size in MB -- mReschke 2012-10-16 SET NOCOUNT ON DECLARE @cmdstr VARCHAR(100) CREATE TABLE #TempTable ( VARCHAR(150), ROW_COUNT INT, Table_Size VARCHAR(150), Data_Space_Used VARCHAR(150), Index_Space_Used VARCHAR(150), Unused_Space VARCHAR(150)) CREATE TABLE #TempTable2 (TableName VARCHAR(150), INT, DataMB INT, IndexMB INT, TotalMB INT, UnusedMB INT) SELECT @cmdstr = 'sp_...
|
post #147 by mreschke Jun 5th 2009 (3077 views)
Concat Rows in MSSQL
https://mreschke.com/138/concat-rows-in-mssql
How to return a comma separated list, in one column, from a field in multiple rows. If you have, for example, email addresses on multiple rows in a table but want to return them as one column, comma separated. Example: Database table ID | report_id | email | 1 | 1 | email1@email.com 2 | 1 | email2@email.com 3 | 1 | email3@email.com I want a return of report_id | email -| 1 | email1@emailcom,email2@email.com,email3@email.com To achieve this, you must create a user defined function which will conc...
|
post #138 by mreschke Mar 3rd 2009 (3950 views)
MSSQL Maintenance
https://mreschke.com/92/mssql-maintenance
SQL Server 2000 Maintenance > The database administrator works like a doctor, keeping databases healthy. Learn the routine maintenance tasks that can help your databases live a long and active life. SQL Server 2000 eliminates the need to run DBCC CHECKDB or DBCC CHECKALLOC. 99% of database failures and corruption with SQL Server 2000 happen due to hardware failures. It is still a good Idea to run DBCC CHECKDB to ensure the overall health of your database prior to backing it up. DBCC C...
|
post #92 by mreschke Jul 23rd 2008 (8644 views)
MSSQL Natural Sort Workaround
https://mreschke.com/76/mssql-natural-sort-workaround
If you have a column that contains some alpha and some numeric data, SQL sees the entire column as alpha and sorts the data differently. Here is an example of an alpha column order by: 105k 10k 120k 20k Another Field Yet Another Field This is obvious since 5 (in 105k) is less than k (in 10k). This is the logical, correct way to sort alpha-numeric data. But I want the order to be 10k, 20k, 105k... In SQL, the column type is defined by the table you are pulling the data from, so if the table colu...
|
post #76 by mreschke Jun 11th 2008 (4492 views)
SQL Divide by Zero Fix
https://mreschke.com/72/sql-divide-by-zero-fix
<p>There are three ways to avoid the "Division by zero encountered" error in your SELECT statement and these are as follows:</p> <ul> <li>CASE statement</li> <li>NULLIF/ISNULL functions</li> <li>SET ARITHABORT OFF and SET ANSI_WARNINGS OFF</li> </ul>
|
post #72 by mreschke May 30th 2008 (8983 views)
MSSQL Date Functions
https://mreschke.com/48/mssql-date-functions
Date and time function tutorials and examples in MSSQL This topic contains a few of the MSSQL date functions and some useful snippets. Dates can get a little confusing in SQL but a good knowledge of their functions is critical for most data queries. Since the date manipulation queries are quite large, its best to set a @variable and reference that variable throughout the code. Remember that the SQL data type has hours, minutes, seconds and sometimes milliseconds also, so you must account for th...
|
post #48 by mreschke Apr 30th 2008 (26343 views)
MSSQL Shared Servers
https://mreschke.com/27/mssql-shared-servers
<ol> <li>Goto Administration Tools -> Component Services<ol> <li>Under Services (local), start the 'Distributed Transaction Coordinator'</li> <li>Goto properties on 'Distributed Transaction Coordinator', Log On tab, make sure account is NetworkServices</li> </ol></li> <li>Under Component Services, expand to My Computer, goto properties on My Computer<ol> <li>MSDTC tab, then click Security Configuration</li> <li>Check 'Network DTC Access'</li> <li>Check 'Allow Remote Administration'</li> <li>Check 'Allow Inbound'</li> <li>Check 'Allow Outbound'</li> <li>Check 'No Authentication Required'</li> <li>Check 'Enable Transaction Internet Protocol (TIP) Transactions'</li> <li>Check 'Enable XA TRansactions'</li> <li>The Acount should be NetworkServices here also</li> </ol></li> <li>Open MSSQL Enterprise Manager, expand to localhost<ol> <li>Open Security</li> <li>Right Click Linked Servers, click New Linked Server...</li> <li>Enter each servers information, on each server</li> </ol></li> </ol>
|
post #27 by mreschke Feb 18th 2008 (2683 views)
SQL Temporary Tables
https://mreschke.com/20/sql-temporary-tables
CREATE TABLE #month0to6 (vin nvarchar(20)) DECLARE @startDate as nvarchar(10), SCF as nvarchar SET @startDate = '10/31/2007' --Insert 0 to 6 month data INSERT INTO #month0to6 (vin) SELECT DISTINCT tblVehicles.VEH_vin FROM tblROTotal --INNER JOIN tblApplications ON tblROTotal.ROH_DLR_APP_ID = tblApplications.APP_ID INNER JOIN tblVehicles ON tblROTotal.ROH_VEH_ID = tblVehicles.VEH_ID INNER JOIN tblMakeModel ON tblVehicles.VEH_MM_ID = tblMakeModel.MM_ID INNER JOIN tblCustomer ON tblCustomer.Cust_I...
|
post #20 by mreschke Jan 25th 2008 (2168 views)
SQL Cursor Examples
https://mreschke.com/6/sql-cursor-examples
DECLARE @server as nvarchar(50), @sql as nvarchar(4000) DECLARE SharedServers CURSOR FORWARD_ONLY FOR SELECT server FROM .ebis_prod.dbo.SharedServerList OPEN SharedServers FETCH NEXT FROM SharedServers INTO @server BEGIN TRANSACTION SET @sql = '' WHILE FETCH_STATUS = 0 BEGIN IF (@server) '' BEGIN --One itteration of SQL goes HERE SET @sql = @sql INSERT INTO .dyna.dbo.TestTable (val1, val2) VALUES (''mReschke'', ''hi'') ' END FETCH NEXT FROM SharedServers INTO @server END exec sp_executesql @sql...
|
post #6 by mreschke Nov 13th 2007 (2585 views)
Showing 1 to 10 of 10 results