|
Apologies for the shouting but this is important.
When answering a question please:
- Read the question carefully
- Understand that English isn't everyone's first language so be lenient of bad spelling and grammar
- If a question is poorly phrased then either ask for clarification, ignore it, or mark it down. Insults are not welcome
- If the question is inappropriate then click the 'vote to remove message' button
Insults, slap-downs and sarcasm aren't welcome. Let's work to help developers, not make them feel stupid.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
For those new to message boards please try to follow a few simple rules when posting your question.- Choose the correct forum for your message. Posting a VB.NET question in the C++ forum will end in tears.
- Be specific! Don't ask "can someone send me the code to create an application that does 'X'. Pinpoint exactly what it is you need help with.
- Keep the subject line brief, but descriptive. eg "File Serialization problem"
- Keep the question as brief as possible. If you have to include code, include the smallest snippet of code you can.
- Be careful when including code that you haven't made a typo. Typing mistakes can become the focal point instead of the actual question you asked.
- Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read. If your problem was answered then edit your message and add "[Solved]" to the subject line of the original post, and cast an approval vote to the one or several answers that really helped you.
- If you are posting source code with your question, place it inside <pre></pre> tags. We advise you also check the "Encode "<" (and other HTML) characters when pasting" checkbox before pasting anything inside the PRE block, and make sure "Use HTML in this post" check box is checked.
- Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
- Please do not post links to your question into an unrelated forum such as the lounge. It will be deleted. Likewise, do not post the same question in more than one forum.
- Do not be abusive, offensive, inappropriate or harass anyone on the boards. Doing so will get you kicked off and banned. Play nice.
- If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
- No advertising or soliciting.
- We reserve the right to move your posts to a more appropriate forum or to delete anything deemed inappropriate or illegal.
cheers,
Chris Maunder
The Code Project Co-founder
Microsoft C++ MVP
|
|
|
|
|
Hello everybody,
It is true that is not a good idea use store procedure actually?
I mean, a) Not a good idea use it in sql
and b) Using o call store procedure in a programming language?
it is so: What is the best way?
|
|
|
|
|
No. Using stored procedures is perfectly fine, and is often preferable to embedding queries directly in your application code.
Whoever told you it's not a good idea clearly doesn't know what they're talking about.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This is something I found some of the younger generation like to promote, put all your logic and processing in the business layer, make the database purely a storage facility. The argument is that you can spawn more processes from the BL to support growth.
IMHO this is utter and absolute bullshit! Databases are optomised to support data PROCESSING as well as storage, that processing is done by stored procedures.
We once did a test, I wrote a SP and a rather brilliant junior wrote a C# process to do the same long running process, the DB was dramatically faster.
Never underestimate the power of human stupidity -
RAH
I'm old. I know stuff - JSOP
|
|
|
|
|
Mycroft Holmes wrote: the younger generation like to promote
Where that typically means one or more of the following.
1. They are inexperienced.
2. They have no idea how to solve problems that show up
3. They have no expectation that problems will even show up.
4. They have no intention of being the one tasked with fixing the problems.
|
|
|
|
|
I have a MySQL table with start and end dates.
E.g rows like this:
start | end
2022-03-01 | 2022-04-10
2021-12-01 | 2022-03-11
2022-01-01 | 2022-04-05
...
I want to count how many of the days in those ranges (all rows) were in April 2022 for instance.
The first record has 10 days in April, the third record has 5 days in April, so the result should be 15.
|
|
|
|
|
So what ideas have you considered so far?
|
|
|
|
|
As you have not shared your attempt at solving this for yourself, nor responded to Craig, I am only going to give you hints to a possible solution. For my test data I used this
declare @demo table (startdate date, enddate date)
insert into @demo (startdate, enddate) values
('2022-03-01', '2022-04-10'),
('2021-12-01', '2022-03-11'),
('2022-01-01', '2022-04-05'); I also hard-coded the start and end dates for the month I am interested in
declare @1stDay date = '2022-04-01';
declare @LastDay date = '2022-04-30'; I then wrote some sql that would convert the dates I had on the table to only those that fell into the month I am looking at. E.g. Something like this
select startdate, enddate
,case when startdate < @1stDay then @1stDay
when startdate > @lastDay then @LastDay
else startdate end as AmendedStartDate
,case when enddate < @1stDay then @1stDay
when enddate > @LastDay then @LastDay
else enddate end as AmendedEndDate
from @demo; I then used those Amended dates in a datediff calculation to get the number of days in each range that fell in April 2022.
This approach is flawed - in that I get 9, 0 and 4 as the results instead of 10, 0, 5. I will leave that as an exercise for you to sort out. I also coded this in MSSQL so you may need to make minor syntactical changes
|
|
|
|
|
Given:
1) Developing a WebService on a DMZ server which will connect back to corporate SQL2019 server.
2) There are lots of other databases on this server, however there will be only one database (DB_X) which these WebServices need to interact.
3) Assume user, WEBAPI_USER, is created.
Also executed: DENY VIEW ANY DATABASE TO WEBAPI_USER;
4) Now, that user cannot see any databases via MS SQL Server Studio, not even the DB_X database which has been granted access
Note: Kind of crazy because if you run the query: SELECT * FROM SYSOBJECTS WHERE XTYPE = 'U', you will get a full list of all the tables. If done some research on this and it appears that WEBAPI_USER would need to become the owner of the databaase to see it in MSSS.
Question: What is everyone else doing to create a limited access MS-SQL user ?
Thank you in advance.
David
|
|
|
|
|
Your description seems to be going backwards.
What you should be doing.
First create the user.
Second give it access to the specific database.
Until you give it access it should not be able to do anything. Which is why your description seems off. Seems to suggest that you created it with access to everything and now you want to restrict that access. So whatever you did to create it in the first place is wrong.
|
|
|
|
|
My database tbl_user has the following columns :
| User_id | Upline | Right_id | Left_id |
+--------+---------+----------+---------+
| 1 | 0 | 4 | 7 |
| 2 | 0 | 6 | 5 |
| 3 | 0 | 0 | 0 |
| 4 | 1 | 0 | 0 |
| 5 | 2 | 0 | 0 |
| 6 | 2 | 0 | 0 |
| 7 | 1 | 0 | 0 |
| 8 | 0 | 0 | 0 |
| 9 | 0 | 0 | 0 |
| 10 | 0 | 0 | 0 |
+--------+---------+----------+---------+
$user_id = 2;
$user_tree = $this->getAllRec("u.user_id",
"tbl_user u",
"WHERE u.Upline = '".$user_id."'
ORDER BY Right_id ASC");
print_r($user_tree);
I want the array `$user_tree` to hold (user_id 5) first, then (user_id 6), how to do that?
I want to print **Left_id** first, then only print **Right_id**. May I know how to do it?
Do I need to use left join or use another query?
modified 3-Apr-22 22:30pm.
|
|
|
|
|
|
Firstly - take note of the previous comment about SQL Injection!
Quote: I want the array `$user_tree` to hold (user_id 5) first, then (user_id 6), how to do that? Then you need to order your results by [user_id] e.g.
select *
from @demo
where upline = 2
order by [User_id]; Quote: I want to print **Left_id** first, then only print **Right_id**. May I know how to do it? I'm not entirely sure what you mean here, but it sounds like you want the columns in a different order in your result. In the example above I used select * - that is not actually good practice. It is much better to list the columns that you want, in the order that you want them - this helps protect any code that is using the results from any subsequent changes to the table schema, such as adding a new column.
However, if you mean you want to sort by one column within the "grouping" of another column then you simply add a list of things to sort by.
This example covers both the scenarios above
select Left_id,Right_id
from @demo
order by Upline, [User_id]; If you meant something else then reply to this solution and I will try to help
|
|
|
|
|
I'm writing a function which will join two collections and two filters for each.
public class Teacher
{
public string Id{ get; set; }
public string Name{ get; set; }
public string TeacherFilter{ get; set; }
...
}
public class Student
{
public string Id{ get; set; }
public string Name{ get; set; }
public string StudentFilter{ get; set; }
public string TeacherId{ get; set; }
...
}
public class TeacherStudents
{
public string Id{ get; set; } -- from teacher
public string Name{ get; set; } -- from teacher
public IEnumerable<Student> Students{get;set;}
}
public class TeacherStudents
{
public string Id{ get; set; } -- from teacher
public string Name{ get; set; } -- from teacher
public IEnumerable<Student> Student{get;set;}
}
public class TeacherStudent
{
public string Id{ get; set; } -- from teacher
public string Name{ get; set; } -- from teacher
...
public Student Student{get;set;}
}
Get(string TeacherFilter,string StudentFilter).
Here is how i implement it
var query = teacherCollection.Aggregate().Match(x => x.TeacherFilter== TeacherFilter);
var query1 = query
.Lookup<Teacher, Student, TeacherStudent>(studentCollection, t => t.Id, s => s.TeacherId, l => l.Student)
.Unwind(x => x.Student, new AggregateUnwindOptions<TeacherStudent>())
.Match(x => x.StudentFilter== StudentFilter)
For the teacher collection, useless data has been filter out which will reduce the data size when doing the lookup(join). But for the student collection, the match stage is appended after the lookup. so does all the data from student will join with teacher behind the scenes? is it possible to filter out some student data before the lookup?
|
|
|
|
|
|
why no one answer it?
modified 10-Mar-22 12:12pm.
|
|
|
|
|
You posted it less than 12 hours ago. Half the world won't have woken up and had a chance to to read it yet.
And since questions here are answered by volunteers, nobody is under any obligation to answer it at all, let alone within a defined time limit.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
i wanna ask.
i forgot my MySQL root password, so i tried to fix it based from this link:
MySQL :: MySQL and Windows :: 4 Resetting the Root Password: Windows Systems[^]
but it still doesn't work and there's few messages, but there's 1 error msg, i.e.:
Failed to set datadir to 'C:\Program Files\MySQL\MySQL Server 8.0\data\' (OS errno: 2 - No such file or directory)
in addition, there's also a warning i.e.:
Can't create test file C:\Program Files\MySQL\MySQL Server 8.0\data\mysqld_tmp_file_case_insensitive_test.lower-test
any1 know how to fix this issue..?
|
|
|
|
|
And does the directory 'C:\Program Files\MySQL\MySQL Server 8.0\data\' actually exist?
|
|
|
|
|
no. but the questions is:
1. why it make such error..? (e.g. tries to access non-exist folder)
2. why it doesn't create the folder by itself..?
3. should the folder created manually..? since it didn't mentioned anything in the article about that folder or even error-handling if it occurred
|
|
|
|
|
chipp_zanuff wrote: the questions is:
1. why it make such error..? (e.g. tries to access non-exist folder)
2. why it doesn't create the folder by itself..?
3. should the folder created manually..? since it didn't mentioned anything in the article about that folder or even error-handling if it occurred
- But why did you set the non-existing folder?
- Why do you think the folder should be created by itself? Well, if you really need such a feature then ask the MySQL developers!
- It looks like the folder should be created manually.
|
|
|
|
|
|
i wasn't
have you read the link that i posted?
i run this command:
mysqld --init-file=C:\\mysql-init.txt
and the error occurred
|
|
|
|
|