SQL: LIKE Searches

There is no pause in there, “LIKE!…searches!” This is a no teeny-bopper zone (unless you want to program stuff, then by all means)! When you know only part of what you’re looking for in a SQL SELECT statement, especially for AJAX auto-complete queries, you will need to employ the all-consuming power of the “LIKE Search” [...]

SQL: Insert Query

The local variables here can be ones you send to your stored procedure, local variables, whatever. The first set of parenthesisW “()” contains the list of fields you want to put data in, like telling someone to stuff a flyer in certain mailboxes (except for that being illegal). The second list is the values or [...]

SQL: Local variables

DECLARE @var1 VARCHAR(50) SET @var1 = ‘hello’ Then you can use it in your SELECT (and other) statements later, like this: SELECT * FROM tablename WHERE welcomemessage = @var1

SQL: While Loop

To repeat a block of code in SQL until a certain condition is reached, you can use a WHILE loop, like this: –DECLARE your vars first DECLARE @var1 INT DECLARE @var2 INT   –the WHILE itself WHILE @var1 > 10 BEGIN @var2 = @var2 + @var1 IF @var2 > 10 BREAK END The IF block [...]

SQL: Create Stored Procedure

CREATE PROCEDURE procedureName @var1 INT, @var2 VARCHAR(255) AS BEGIN SELECT * FROM tablename WHERE fieldname = @var1 END

SQL: Create Temp Table

CREATE TABLE #tablename( id INT )