Categories
MySQL

Creating a Stored Procedure – MySQL 5.0

DELIMITER$$    CREATE PROCEDURE testing(IN ID INT)      BEGIN         SELECT COUNT(*) AS numrows FROM clients.clients_domain;      END$$ DELIMITER; The “DELIMITER $$” statement causes MySQL to use two dollar signs ($$) as it’s end-of-line delimiter, instead of a semi-colon (;). This will allow any SQL between the BEGIN and END to have a semi-colon at the end of the […]

Categories
ASP.NET

Change datagrid cell properties using ASP.NET C#

public void dgBoundItems(object sender, DataGridItemEventArgs e) { foreach(TableCell cell in e.Item.Cells) { ///e.Item.DataSetIndex = row ///e.Item.Cells.GetCellIndex(cell) = column if (e.Item.Cells.GetCellIndex(cell) == 2 && e.Item.DataSetIndex > 0) { ///If the salary is less than 5000 the color must be red. if (Convert.ToInt32(cell.Text.Trim()) < 5000) { cell.ForeColor = Color.Red; } } } }

Categories
SQL

Finding Duplicates with SQL

Here’s a handy query for finding duplicates in a table using the GROUP BY and HAVING statement. Suppose you want to find all email addresses in a table that exist more than once: SELECT email, COUNT(email) AS NumOccurrences FROM users GROUP BY email HAVING ( COUNT(email) > 1 ) You could also use this technique […]

Categories
ASP.NET C# JavaScript VB.NET

Inline IF’ Statement

C# string s; s = (true ? “True” : “False”); //s will be “True” VB.NET Dim s As String s = If(True, “True”, “False”) ‘s will be “True” ‘In the following you cannot rely on a particular function ‘not being called if the other argument is selected by Expression ‘(notice IIf vs. If) s = […]

Categories
ASP.NET

DateTime Format String

DateTime now = new DateTime(2006, 9, 07, 15, 06, 01, 08, DateTimeKind.Local); now.ToString(); //”09/27/2006 15:06:01″ Year now.ToString(“%y”); //”6″ now.ToString(“yy”); //”06″ now.ToString(“yyy”); //”2006″ now.ToString(“yyyy”); //”2006″ Month now.ToString(“%M”); //”9″ now.ToString(“MM”); //”09″ now.ToString(“MMM”); //”Sep” now.ToString(“MMMM”); //”September” Day now.ToString(“%d”); //”7″ now.ToString(“dd”); //”07″ now.ToString(“ddd”); //”Thu” now.ToString(“dddd”); //”Thursday” Hour now.ToString(“%h”); //”3″ now.ToString(“hh”); //”03″ now.ToString(“hhh”); //”03″ now.ToString(“hhhh”); //”03″ now.ToString(“%H”); //”15″ now.ToString(“HH”); //”15″ […]

Categories
ASP.NET

Problems with MagicAjax

I added what is below to my web.config file: <httpModules> <add name=”MagicAjax” type=”MagicAjax.MagicAjaxModule, MagicAjax”/> <add name=”ScriptModule” type=”Microsoft.Web.Services.ScriptModule”/> </httpModules> And I got: Could not load file or assembly ‘MagicAjax’ or one of its dependencies. The system cannot find the file specified. (C:\Inetpub\wwwroot\TheTracker\web.config line 48) The solution I found that worked was adding the MagicAjax assembly to […]

Categories
SQL SQL Server

SQL: YYYYMMDD

SELECT CONVERT(VARCHAR(8), GETDATE()-365, 112) This is a way to query and get the date in the following format: YYYYMMDD I came across some dates saved in the database in this format as a varchar and had to use this to initially get the date and then convert it from and integer to varchar.

Categories
SQL SQL Server

Standard Date Formats

View Standard Date Formats

Categories
SQL SQL Server

Back up the transaction log for the database to free up some log space.

Error: Back up the transaction log for the database to free up some log space. To recover from a full transaction log If the log is 100% full you cannot truncate it by backing it up, since the backup has to be recorded in the transaction log. For version 6.5, use: DUMP TRANSACTION dbName WITH […]

Categories
SQL SQL Server

sp_spaceused (Transact-SQL)

Displays the number of rows, disk space reserved, and disk space used by a table, indexed view, or SQL Server 2005 Service Broker queue in the current database, or displays the disk space reserved and used by the whole database.