Using Modal Popup and Rounded Corners Extenders in Conjunction
Tuesday, April 7, 2009 at 09:29AM I
recently ran into an issue when trying to use the
Hopefully
it will help any of you out there who might run into the same issue.
Tuesday, April 7, 2009 at 09:29AM I
recently ran into an issue when trying to use the
Hopefully
it will help any of you out there who might run into the same issue.
Wednesday, March 25, 2009 at 03:38PM Updating
a table with data from another table in the same database is something I find
myself doing pretty frequently – I use this example quite a bit so I
thought I’d post it for easy reference. It facilitates the updating of
one table with data from another table, using a key relationship:
Take for
example TableA
with the following columns…
ModelId
(PK)
CarName
VehicleDescription
CarSerialId
And TableB with the following columns…
MaintenanceId (PK)
ModelId
(FK)
MaintenanceHist
OwnerName
CarDescription
If I
wanted to update the CarDescription column in TableB with the data in the VehicleDescription
column in Table A, joining on ModelId, this is how it
would be done:
UPDATE [DatabaseName].[dbo].[TableB]
SET CarDescription
= TableA.VehicleDescription
FROM TableB,
TableA
WHERE TableB.ModelId = TableA.ModelId
Thursday, December 18, 2008 at 05:14PM I’ve run into a few situations in which I needed to use a variable in a ‘TOP’
clause in a stored procedure. SQL Server won’t allow a variable to be used as
the top number of records to be selected:
(SqlServerError: Incorrect syntax near '@top'.).
Usually setting ROWCOUNT would be a good alternative, however I recently
ran into a situation in which this would not give me the intended results.
Here’s why: The stored procedure that was created used a TOP selection
criteria in a subselect – ROWCOUNT applies to the final result set of the query.
The Solution: By using the Row_Number() function, row numbers can be assigned
to items in the subselect. In this example, the subselect is numbering rows for the top
taxpayers in a tax region using
Row_Number() OVER (ORDER BY c.Total DESC) AS [RNumber]
The order by clause designates that the owner with the highest total will have a
row number of 1 and so on. In the containing query, it can be specified to only
show results for records with a row number less that the parameter passed to
the stored procedure.
@iNumRows INT
-- (This is our variable to hold the number of
-- Results the user wished to see)
SELECT e.nName, e.nAddress
FROM
(SELECT Row_Number() OVER (ORDER BY c.Total DESC) AS [RNumber],
SUM(c.Total) as Total, c.OwnerName
FROM
(SELECT DISTINCT b.OwnerName, a.land + a.Imp AS total,
a.n1stTDP + a.n2ndTDP AS TotDelq
FROM RM_TaxDuplicate a, RM_TaxDuplicateAddress b
WHERE a.nTaxDistrict = 25006
AND SUBSTRING(CAST(a.nLandUseCode AS VARCHAR(5)), 1, 1) = 5
AND a.nParcelType = 400 AND a.nParcelId = b.ParcelId
AND a.nFiscalYear = 2007) c
GROUP BY c.OwnerName, c.Total, c.TotDelq) d,
RM_TaxDuplicate e
WHERE e.nTaxDistrict = 67388 AND d.RNumber < @iNumRows
-- @iNumRows should be incremented by 1 when using the less than
-- comparison. (ie: if they want to see top 30, we would want
-- to look at rows less than 31)
AND g.OwnerName = d.OwnerName AND e.nFiscalYear = 2007
ORDER BY d.Total DESC, e.nOwnerName
For more options on how to use the TOP clause with a variable, try checking
out http://sqlserver2000.databases.aspfaq.com/how-do-i-use-a-variable-in-a-top-clause-in-sql-server.html