Viewing 15 posts - 16 through 30 (of 7,597 total)
SELECT TOP (1) reg
FROM ( VALUES(@var1), (@var2) ) AS datetimes(reg)
ORDER BY reg DESC
This approach will be really useful if you ever have to add a 3rd (4th,...
March 19, 2025 at 6:16 pm
DROP TABLE IF EXISTS #view_names;
CREATE TABLE #view_names (
view_name nvarchar(100) PRIMARY KEY
);
INSERT INTO #view_names
VALUES('>--->YOUR_VIEW_NAME_TO_SEARCH_FOR_GOES_HERE<---<')
/*, ('another_view_name_could_go_here') ... */
DROP TABLE IF...
March 17, 2025 at 2:45 pm
Exact code works for me in SQL 2022.
Maybe use bigint rather than int!?:
declare @status as bigint=83457678;
;with nums(num, [2power_Num], bitcheck)
as
(
SELECT Num, POWER(2, CAST(Num AS bigint)), (@status &...
March 13, 2025 at 6:13 pm
It's also possible that you were missing critical index(es) that were forcing full scans of the table. Every issue is not necessarily always exactly the same as one that happened...
March 6, 2025 at 12:22 am
Is there any circumstances where you would allow code with a 'SELECT * ' to go into production?
I believe this should NEVER happen. There is a discussion that...
February 21, 2025 at 8:39 pm
SELECT
LEFT(Bname, CHARINDEX(' ', BName) - 1) AS BName,
MAX(CASE WHEN BName LIKE '% Start%' THEN StartDate ELSE '' END) AS...
February 21, 2025 at 6:02 pm
I don't know of a super-slick way to do this off the top of my head:
SELECT DISTINCT run_date, run_time,
CAST(CAST(run_date AS varchar(8)) +...
February 10, 2025 at 3:32 pm
OOPS, SORRY, I did it back'ards.
SELECT [Profile ID]
FROM dbo.table_name
GROUP BY [Profile ID]
HAVING COUNT(DISTINCT [Customer ID]) =
(SELECT COUNT(DISTINCT [Customer ID]) FROM dbo.table_name)
February 7, 2025 at 7:18 pm
SELECT [Customer ID]
FROM dbo.table_name
GROUP BY [Customer ID]
HAVING COUNT(DISTINCT [Profile ID]) = (SELECT COUNT(DISTINCT [Profile ID]) FROM dbo.table_name)
February 7, 2025 at 3:08 pm
You should definitely switch the key order on the lookup table, i.e., not:
PRIMARY KEY CLUSTERED ( iid, cart_id )
but instead do this:
PRIMARY KEY CLUSTERED ( cart_id, iid )
February 3, 2025 at 5:21 pm
You could also likely work around changing the db code using views, if changing the code is just too difficult to do quickly by hand. Typically that doesn't cause performance...
January 30, 2025 at 10:08 pm
Yes.
EXEC sys.sp_rename 'dbo.table_name.column_name', 'new_column_name', 'COLUMN'
for each table column that you want to rename.
January 30, 2025 at 7:08 pm
OOPS, quite right, I should have used ">=" and "<" rather than "BETWEEN".
January 11, 2025 at 2:43 am
I have NOT uber-tuned this, just trying to get something that works (so many people here obsess over every microsecond). If you have a lot of rows, more tuning might...
January 10, 2025 at 11:03 pm
SELECT G.Gage_ID 'ID', G.Model_No 'Model', L.LocationName 'Room', D.GageDescriptionName 'Desc',C.Calibration_DateTime 'Cal', G.Gage_SN 'S/N', S.StatusName 'Status', C.NextDue 'Due'
FROM GAGETRAK.Gages G
JOIN GAGETRAK.Locations L ON G.StorageLocation_RID_FK=L.Location_RID
JOIN GAGETRAK.GageDescriptions D ON G.GageDescription_RID_FK=D.GageDescription_RID
JOIN GAGETRAK.Status S ON G.Status_RID_FK=S.Status_RID...
January 8, 2025 at 11:44 pm
Viewing 15 posts - 16 through 30 (of 7,597 total)