Viewing 15 posts - 961 through 975 (of 1,391 total)
https://www.sqlservercentral.com/blogs/tally-tables-in-t-sql
declare
@start_yr int=2020,
@years int=20;
;with
tally(n) as
(
...
July 12, 2020 at 10:16 am
The OP could generate as many years as needed with a tally table 🙂
declare
@start_yr int=2020,
@years...
July 11, 2020 at 4:52 pm
Fwiw, adding meta data like ('ORD'+number and 'MO'+date) to database keys is not the best practice. If you're stuck with it perhaps it's possible to add constraints which only allow...
July 8, 2020 at 12:30 pm
Isn't this the same question from 3 weeks ago?
There were some good answers offered
July 8, 2020 at 11:45 am
Another way
select s.salesman_id, s.salesman
from
#salesman s
cross apply
(SELECT COUNT(*) cnt FROM #customer c WHERE c.salesman_id=s.salesman_id) xa
where
xa.cnt>1;
July 3, 2020 at 4:07 pm
drop table if exists #salesman;
go
create table #salesman(salesman_id int, salesman varchar(20));
go
insert #salesman(salesman_id, salesman) values
(1, 'Tedd'),
(2, 'Fred'),
(3, 'Ed');
drop table if exists #customer;
go
create table #customer(customer_id int, salesman_id int, customer...
July 3, 2020 at 2:45 pm
My work is typically a .NET front end and SQL back end, so I favor having stored procedures fail and letting the front end handle the error.
No...
June 27, 2020 at 2:01 pm
Ok now it makes sense to me. For some reason I thought the object_id() was going in the query and not the cursor. In Azure SQL it's not allowed to...
June 26, 2020 at 12:23 pm
schleep, that sounds interesting. It's a 3 part naming convention? Is there a . missing before dbo.? Maybe it's simpler to query the sys table and idk. It could be...
June 25, 2020 at 10:13 pm
Thanks Roger. Regarding "Errors Unaffected by a Try/Catch Construct" the issues are mitigate-able (imo (all of what follows)) if handled properly (knock on wood). I must be biased tho because...
June 25, 2020 at 4:49 pm
Declare @msg varchar(100)
DECLARE db_cursor CURSOR FOR
SELECT Name FROM Alldatabases
WHERE OBJECT_ID(Name + 'dbo.<tablename>') IS NOT NULL
ORDER BY Name
OPEN wh_cursor
In your post, you had 2 tables, Settings and Employee, so maybe...
June 25, 2020 at 2:48 pm
TRY/CATCH doesn't catch everything. In fact it won't catch most of the things you really want it to so I simply avoid it completely. Nothing worse than an unreliable...
June 25, 2020 at 2:46 pm
select
a.[name],
sum(iif(b.gender='M', 1, 0)) m_count,
sum(iif(b.gender='F', 1, 0)) f_count
from
#department a
join
#employee b on a.departmentID = b.departmentID
group by
...
June 25, 2020 at 1:50 pm
There's a lot going on in the code which could be looked at. Instead of EXEC(@qry) where the parameters are strung together it could be parameterized using sp_executesql. In terms...
June 18, 2020 at 5:09 pm
Viewing 15 posts - 961 through 975 (of 1,391 total)