T-SQL Update with Inner Join

Below is an example of an Update that has an Inner Join

UPDATE
    Taskevent
SET
    RebateProcessed = 1
FROM
    TaskEvent
INNER JOIN
    TaskEventAsset
    ON TaskEvent.Id = TaskEventAsset.Id
WHERE
    PatientId = @PatientID
AND
    JobDate < @PriorTo
AND
     ConcentratorId = @ConcentratorId


SQL Grant Execute

Found an article that had a nice SQL script to assign execute permissions to a user in SQL2000

Here is the script

DECLARE @sql nvarchar(4000)

DECLARE @db  sysname ;
SET @db = DB_NAME()

DECLARE @u   sysname ;
SET @u = QUOTENAME('')

SET @sql ='select ''grant exec on ''
        + QUOTENAME(ROUTINE_SCHEMA) + ''.''
        + QUOTENAME(ROUTINE_NAME) + '' TO ' + @u
        + ''' FROM INFORMATION_SCHEMA.ROUTINES ' +
        'WHERE OBJECTPROPERTY(OBJECT_ID(ROUTINE_NAME),''IsMSShipped'') = 0'

EXEC master.dbo.xp_execresultset @sql,@db


Remember "null" is not the same as "DBNull"

When supplying null values to stored procedures, remember that you have to set the value to DBNull…

if (_UserId == null)
{
    cmd.Parameters.Add(new SqlParameter("@UserId",System.DBNull.Value ));
}
else
{
    cmd.Parameters.Add(new SqlParameter("@UserId", _UserId));
}


Next Entries