Viewing 15 posts - 976 through 990 (of 1,413 total)
Always good to hear differing methods. Optional parameters are the bane of my life, but that's a reasonable well established method of dealing with it, and fairly low cost...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 14, 2020 at 12:36 pm
Thanks all for your responses,
My question now is Why? Why does not works as is ? we are suggested to a very strict change control policy
Thanks
Why questions are tricky! Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 14, 2020 at 12:28 pm
Also not a good idea... Give this a read: https://www.red-gate.com/simple-talk/sql/t-sql-programming/how-to-confuse-the-sql-server-query-optimizer/
Ha, my recommendation is 2 procs so there's nothing to confuse. If the OP wants to keep dealing with avoidable...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 14, 2020 at 11:41 am
Yup, of course NULL does not equal NULL, but the fldinfo cannot be NULL (confirmed by OP).
So presumably @Parameter is optional and can be NULL. In which case the...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 14, 2020 at 11:15 am
Using
WHERE @parameter IS NULL OR fldinfo = @parameter
You are comparing against a single value
It's not the same query as the one the OP posted. NULL does not equal NULL
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 13, 2020 at 2:29 pm
SELECT *
FROM tblInfo
WHERE @parameter IS NULL OR fldinfo = @parameter
Not quite the same as what the OP posted. Here's another way but readability is not...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 13, 2020 at 11:24 am
Imo it's easier to express as 2 queries
drop table if exists test_tblinfo;
go
create table test_tblinfo(fldinfo int);
go
insert test_tblinfo values (null), (1);
declare
@parameter ...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 12, 2020 at 11:45 am
https://www.sqlservercentral.com/blogs/tally-tables-in-t-sql
declare
@start_yr int=2020,
@years int=20;
;with
tally(n) as
(
...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
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...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
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...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
July 8, 2020 at 12:30 pm
Isn't this the same question from 3 weeks ago?
There were some good answers offered
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
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;
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
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...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
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...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
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...
Aus dem Paradies, das Cantor uns geschaffen, soll uns niemand vertreiben können
June 26, 2020 at 12:23 pm
Viewing 15 posts - 976 through 990 (of 1,413 total)