 |
 |
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 all. I am writing a C# program. The program downloads an rdl report and then examines the SharedDataSetReference tag of the XML.
From this information, I can get the server path to the shared dataset. What I need to do is to use the shared dataset name to get the name of the stored procedure that the dataset gets it's information from. I assume that I would query the Report Server Database. The dataset uses a shared datasource as well. I have been trying to figure out how to do this for a while now, and I cannot.
I am not giving up though. If I figure it out, I will come back and post the solution, but I would appreciate any help I can get.
Thanks,
David
|
|
|
|
 |
From reading this[^] the shared datasource may have nothing to do with a database but is a file on the REPORT server, its source may be anything, Excel, CSV, or a web service query.
Never underestimate the power of human stupidity
RAH
|
|
|
|
 |
Thank you for your reply. All of our shared datasets point to stored procedures.
I think I just figured out a solution. I have done this before. I don't know why I didn't think of it before. I am going to have my program download the shared dataset as an .rds file and then look at the xml tag CommandText in the rds file.
|
|
|
|
 |
Hi All,
I am executing a dtsx package from C# code, what dtsx package does is, it simply reads data from .txt file and writes into another .txt file. I have two connections "Flat File Connection Manager" and "Flat File Connection Manager 1", I am calling that package with FileWatcher application which invokes when file changes or created etc. But when I am trying to execute the package, its giving me Success message but its not able to create the destination file. But package is able to create the destination file when its executed from SSDT (BIDS) using start debugging but the same package when its called from the C# code, its not generating the destination flat file.
I am not understanding is it a permission issue or something I am missing in my Code?
Can anybody please help me I am searching in google and trying with different combinations, any kind of help would be greatly helpful - thanks in advance.
private static void OnCreated(object source, FileSystemEventArgs e)
{
string strFileExt = (Path.GetExtension(e.FullPath) ?? string.Empty).ToLower();
string directoryFullPath = Path.GetDirectoryName(e.FullPath);
if (Regex.IsMatch(strFileExt, @".txt|.csv", RegexOptions.IgnoreCase))
{
Package _package = null;
Application app = new Application();
string dtsPackPath = ConfigurationManager.AppSettings["SSISPackagePath"];
_package = app.LoadPackage(dtsPackPath, null);
_package.Connections["Flat File Connection Manager"].ConnectionString = e.FullPath;
_package.Connections["Flat File Connection Manager 1"].ConnectionString = directoryFullPath + @"\Test" + DateTime.Now.Year.ToString()
+ DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString()
+ DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString()
+ DateTime.Now.Second.ToString() + DateTime.Now.Millisecond.ToString() + ".txt";
var res = _package.Execute();
if (res == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success)
{
string message = "Package Executed Successfully....";
}
}
while (Console.Read() != 'q') ;
}
Now I did try it by putting OLEDB connection for destination, still when package runs from Visual Studio yields o/p but when run from the Console app, it doesn't give me any o/p neither in the o/p file nor in the Database table
Here is the code for writing into Database table
private static void OnCreated(object source, FileSystemEventArgs e)
{
string strFileExt = (Path.GetExtension(e.FullPath) ?? string.Empty).ToLower();
string directoryFullPath = Path.GetDirectoryName(e.FullPath);
if (Regex.IsMatch(strFileExt, @".txt|.csv", RegexOptions.IgnoreCase))
{
Package _package = null;
Application app = new Application();
string dtsPackPath = ConfigurationManager.AppSettings["SSISPackagePath"];
string sqlServerConnectionString = ConfigurationManager.AppSettings["SqlServerConnectionString"];
_package = app.LoadPackage(dtsPackPath, null);
_package.Connections["Flat File Connection Manager"].ConnectionString = e.FullPath;
_package.Connections["BSCWD725128.DTS_Testing"].ConnectionString = sqlServerConnectionString;
var res = _package.Execute();
if (res == Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success)
{
string message = "Package Executed Successfully....";
}
}
while (Console.Read() != 'q') ;
}
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
modified yesterday.
|
|
|
|
 |
I got it resolved my friends, no worries right now
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
 |
we have been working on application which use ..mdb file to store the data ...
now if any one copies the database from c drive opens it which is password protected make changes and overwrite it back on program files ... is there any way we can find this out ... if someone has touched the db ...
file is password protected but in case person knows the password ...
like if we made some mistake in some entry and we open the db correct the entry and save it and then overwrite it in program files ... the application keeps working normally after that ...
Please let me know if there is any software or method to find that out .
|
|
|
|
 |
Well for a start .mdb indicates you are using Access which is a single user tool. Why is someone able to copy the file from your machine! Oh wait you probably have it on a server and a number of clients use it - WRONG TOOL for the job. Move to SQL Server.
Password protection is supposed to PROTECT your file, you are not managing your passwords well enough!
You can make your folder readonly so they can copy but not return the file. Not sure if this will stop you writing to the database - test it.
It seem you are using the wrong tool in a badly managed environment, it is unlikely this will have a happy ending.
Never underestimate the power of human stupidity
RAH
|
|
|
|
 |
Mycroft Holmes wrote: You can make your folder readonly so they can copy but not return the file. Not sure if this will stop you writing to the database - test it.
It will.
Making the folder read-only would even stop you reading the database, because this is MS Access. In order to open the database, it has to create a lock file in the same folder.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
 |
It's been 15 years since I touched Access, does that represent short memory loss I wonder.
While I think Access has it's place, the moment it moves to a server or shared drive it becomes the wrong tool for the job.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
 |
Hi All.
I Have a SQL Server.This server have link server to Oracle DB.
I can select anything from oracle DB through this SQL server such as.
Select * from [ORacleDBName]..[SIDName].[OracleTable]
But now I don't know how to update oracle db from SQL.
Pleas help me.
|
|
|
|
|
 |
I also want to create a new table in oracle DB through SQL Server such as.
Select * from SQL Server into OracleLinkDB.
|
|
|
|
 |
I would suggest you study the documentation for both Oracle and SQL.
|
|
|
|
 |
If you follow the link Richard supplied and look down the left menu - 18 items down you will find some interesting reading.
You need to learn to do some thinking and research on your own!
Never underestimate the power of human stupidity
RAH
|
|
|
|
 |
Select * from SQL Server into OracleLinkDB is SQL Server Syntax.
Oracles syntax is CREATE TABLE new_table AS (SELECT * FROM old_table);
I'd recommend checking out techonthenet.com[^] for comparing the syntax of different databases.
|
|
|
|
 |
I Mean I Want to update Oracle DB through SQL Server Management Studio via Link Server.
|
|
|
|
 |
Hello all. I have the following Stored Procedure:
ALTER PROCEDURE [EventPortion].[24Start]
AS
IF object_id('[IntegratedTest1].[EventPortion].[244Q1]') is not null
DROP TABLE [IntegratedTest1].[EventPortion].[244Q1]
IF object_id('[IntegratedTest1].[EventPortion].[244Q2]') is not null
DROP TABLE [IntegratedTest1].[EventPortion].[244Q2]
IF object_id('[IntegratedTest1].[EventPortion].[244Q3]') is not null
DROP TABLE [IntegratedTest1].[EventPortion].[244Q3]
SELECT * Into [IntegratedTest1].[EventPortion].[244Q1] FROM IntegratedTest1.Event.MOE_2_4_DE_4_Q1
While (object_id('[IntegratedTest1].[EventPortion].[244Q1]') is null)
Begin
WAITFOR DELAY '00:00:00.001';
End
Begin
WAITFOR DELAY '00:00:01.000';
End
SELECT * Into [IntegratedTest1].[EventPortion].[244Q2] FROM IntegratedTest1.Event.MOE_2_4_DE_4_Q2
While (object_id('[IntegratedTest1].[EventPortion].[244Q2]') is null)
Begin
WAITFOR DELAY '00:00:00.001';
End
SELECT * Into [IntegratedTest1].[EventPortion].[244Q3] FROM IntegratedTest1.Event.MOE_2_4_DE_4_Q3
I want this code to drop the 3 tables if they exist. This works.
Then run the first Select Into.
IntegratedTest1.Event.MOE_2_4_DE_4_Q2 depends on (Selects from) 244Q1. The problem that I am having is that the second Select Into is being executed and I am getting a binding error that 244Q1 doesn't exist. So, the While Is Null Wait For loops are not working. If I just execute the Wait For 1 second delay, that does take 1 second to execute. If I just run the first select into and the 1 second delay, it takes about 1 second to execute. But if I run the first and second select into with the delays in between, there is no delay. I immediately get the binding error.
Is there anything I can do about this seemingly odd behavior?
Thanks,
David
Edit: I figured out a solution and wanted to post it.
I modified the stored procedure to:
ALTER PROCEDURE [EventPortion].[24Start]
AS
DROP TABLE [IntegratedTest1].[EventPortion].[244Q1]
DROP TABLE [IntegratedTest1].[EventPortion].[244Q2]
DROP TABLE [IntegratedTest1].[EventPortion].[244Q3]
SELECT * Into [IntegratedTest1].[EventPortion].[244Q1] FROM IntegratedTest1.Event.MOE_2_4_DE_4_Q1
SELECT * Into [IntegratedTest1].[EventPortion].[244Q2] FROM IntegratedTest1.Event.MOE_2_4_DE_4_Q2
SELECT * Into [IntegratedTest1].[EventPortion].[244Q3] FROM IntegratedTest1.Event.MOE_2_4_DE_4_Q3
DROP TABLE [IntegratedTest1].[EventPortion].[245Q1]
DROP TABLE [IntegratedTest1].[EventPortion].[245Q2]
DROP TABLE [IntegratedTest1].[EventPortion].[245Q3]
SELECT * Into [IntegratedTest1].[EventPortion].[245Q1] FROM IntegratedTest1.Event.MOE_2_4_DE_5_Q1
SELECT * Into [IntegratedTest1].[EventPortion].[245Q2] FROM IntegratedTest1.Event.MOE_2_4_DE_5_Q2
SELECT * Into [IntegratedTest1].[EventPortion].[245Q3] FROM IntegratedTest1.Event.MOE_2_4_DE_5_Q3
I didn't mention before that this stored procedure is run from a C# front-end. I have code which extracts the SQL from the stored procedure and passes it to the following method:
private void ParseStartProcedure(string spText)
{
spText = spText.Replace("\r", " ");
spText = spText.Replace("\t", " ");
spText = spText.Trim();
string[] queryPieces = Regex.Split(spText.ToLower(), " as ");
string[] queryLines = Regex.Split(queryPieces[1], "\n");
for (int i = 0; i < queryLines.Length; i++)
{
if (queryLines[i] != "")
{
string query = queryLines[i];
SqlCommand cmd = new SqlCommand(query, m_dbSettings.sqlMetadataDbConn);
try
{
cmd.ExecuteNonQuery();
}
catch (SqlException ex)
{
string message = ex.Message;
}
}
}
}
modified 22-Sep-16 19:41pm.
|
|
|
|
 |
Dear all,
Currently, I need to create a database for control Process in manufacturing.
One Item have got many LotNo,
One LotNo thought many Process(ex: Process A, Process B,Process C...)
with every Process maybe yes or maybo no use Material
How can I build database for:
Select all Lot no and Process by ItemNo
Slect all Process and status in every Process by LotNo
Input ItemNo show all information about Material used on every Process
This is my database:
Item(Id_Item,ItemNo,ItemName)
Lot(Id_Lot,Item_Id,LotNo)
Process(Id_Process, ProcessNo, ProcessName)
Lot_Process(Id,Lot_Id,Process_Id)
Material(Id,Process_Id,MaterialName, Quantity)
|
|
|
|
 |
I am importing Data from excel-sheet to our sql server which comes from another system. Example In our sql server database Client name is Zee Entertainment Limited but in Another System Client Name is Zee Ent. ltd. or any other name format. In this way there are 10 thousands of records which is having data variations and We can not change our data which is connected to another business.
Kindly give me solution.
Thanks & Regards
Shankar Chaurasia
|
|
|
|
 |
Create a mapping table that maps the company name from the 2 source systems to your system.
This will work but is a solution fraught with disaster, presumably there is no control of the source systems input (excel as a data source ) so whenever a user miss types a company name your mapping goes into the garbage.
Never underestimate the power of human stupidity
RAH
|
|
|
|
 |
I would take a look at fulltext search.
You can add synonyms to the index, and it can also search for proximity terms (spilling errors).
The subject is much to big to cover in a forum answer, but you can start reading here[^] to get a feeling for what can be done.
|
|
|
|
 |
Hello,
I'm having some problems getting an update running. I have done similar updates some times without problems (MySql instead of MariaDB). Maybe I'm too tired today to see the problem, it was a long working day...
Maybe someone can illuminate me
Table:
CREATE TABLE ps_data.test (
Test_ID int(11) NOT NULL AUTO_INCREMENT,
Idx int(11) NOT NULL,
Grp int(11) DEFAULT NULL,
PRIMARY KEY (Test_ID)
)
ENGINE = INNODB
AUTO_INCREMENT = 10
AVG_ROW_LENGTH = 1820
CHARACTER SET utf8
COLLATE utf8_unicode_ci;
Sample-Data:
INSERT INTO ps_data.test(Test_ID, Idx, Grp) VALUES
(1, 1, 1);
INSERT INTO ps_data.test(Test_ID, Idx, Grp) VALUES
(2, 2, 1);
INSERT INTO ps_data.test(Test_ID, Idx, Grp) VALUES
(3, 3, 1);
INSERT INTO ps_data.test(Test_ID, Idx, Grp) VALUES
(4, 4, 1);
INSERT INTO ps_data.test(Test_ID, Idx, Grp) VALUES
(5, 5, 2);
INSERT INTO ps_data.test(Test_ID, Idx, Grp) VALUES
(6, 6, 2);
INSERT INTO ps_data.test(Test_ID, Idx, Grp) VALUES
(7, 7, 2);
INSERT INTO ps_data.test(Test_ID, Idx, Grp) VALUES
(8, 8, 2);
INSERT INTO ps_data.test(Test_ID, Idx, Grp) VALUES
(9, 9, 2);
Update commands (none working):
UPDATE test
SET Idx=(SELECT COALESCE(MAX(tbl.Idx), 0)+1 FROM (SELECT * FROM test) tbl WHERE tbl.Grp=1)
WHERE Test_ID=1
UPDATE test
SET Idx=(SELECT COALESCE(MAX(tbl.Idx), 0)+1 FROM (SELECT * FROM test WHERE Grp=1) tbl)
WHERE Test_ID=1
UPDATE test t, (SELECT * FROM test WHERE Grp=1) tbl
SET t.Idx= (SELECT COALESCE(MAX(tbl.Idx), 0)+1)
WHERE t.Test_ID=1
The first update command produces even a null result on the MAX() function. Strange...
Best Regards,
Raul
modified 17-Sep-16 15:09pm.
|
|
|
|
 |
Have you tried the update statement as a select just to see if it returns the expected value.
I would also change select * from test to select Idx from test
Never underestimate the power of human stupidity
RAH
|
|
|
|
 |
yes, normally I would use Select Idx, but on samples I use the most simplified syntax.
The bad news is that the first two examples work on MySql but not on MariaDB. The third syntax doesn't work on any DBMS, but I never used it and got it yesterday from the internet because I was desperated.
I always thought that MariaDB is fully compatible to MySql, but this is unfortunatelly not true. Really bad news for those who migrated a productive system from MySql to MariaDB and are using systax like that :(
|
|
|
|
 |
In terms of db object like table,store proc,view ect what are difference is there between sql server express and sql server localdb ?
What we can do with sql express and what we can't with localdb? What missing in localdb compared with sql express db?
please share the knowledge.
tbhattacharjee
|
|
|
|
 |
Tridip Bhattacharjee wrote: please share the knowledge. Has already been shared. Google, and you'll find blogs/articles like this[^] one.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
 |
Hi
I'm running the below query, I want to get records for multiple fundCodes in this case Bateleur and Tower Fund.I'm only getting records for Bateleur only from 2016-04-20 to 2016-04-29.
Thank you
Declare @FundCodes VarChar(Max)='Bateleur|Tower Fund', @StartDate DateTime='2016/04/20',
@EndDate DateTime='2016/04/29',
@Zero integer=1,
@LongShortAll integer = 0, @PhysEff integer = 0
select fulldate into #TableDates
from AssetData.dbo.Calendar cal where cal.FullDate between @StartDate and @EndDate
and IsWeekDay = 1 and IsHoliday = 0
SET NOCOUNT ON;
declare @NextDate DateTime
set @NextDate = @StartDate
declare @TempValues table(FundCode varchar(200),EffectiveDate DateTime, Value Float)
declare @fundcodestable table (ID int, fundcode varchar(300))
declare @Val float
declare @DateCounter int = 0
select @DateCounter = count(Fulldate) from #TableDates
declare @Date date
while @DateCounter <> 0
begin
set @Date = (select top 1 fulldate from #TableDates order by 1)
insert into @fundcodestable
select pn, s
from StagedFundReportingData..FnxSplit('|', @fundcodes)
Declare @counterFundId int = 0
select @counterFundId = count(fundcode) from @fundcodestable
declare @fundC varchar(300)
while @counterFundId <>0 and @NextDate<=@EndDate
begin
set @fundC = (select top 1 fundcode from @fundcodestable)
Set @Val = 0
if @Zero = 0
begin
if @LongShortAll = 0 begin
exec GetFundValue @fundC, @NextDate, @Val output
end else begin
if @LongShortAll = 1 begin
if @PhysEff = 0 begin
exec GetFundValueLongOnly @fundC, @NextDate, @Val output
end else begin
exec GetFundUnderlyingEffectiveValueLongOnly @fundC, @NextDate, @Val output
end
end else begin
if @PhysEff = 0 begin
exec GetFundValueShortOnly @fundC, @NextDate, @Val output
end else begin
exec GetFundUnderlyingEffectiveValueShortOnly @fundC, @NextDate, @Val output
end
end
end
end
else
begin
If @LongShortAll = 0 begin
exec GetFundValue_ZeroFutures @fundC, @NextDate, @Val output
end else begin
if @LongShortAll = 1 begin
if @PhysEff = 0 begin
exec GetFundValueLongOnly_ZeroFutures @fundC, @NextDate, @Val output
end else begin
exec GetFundUnderlyingEffectiveValueLongOnly_ZeroFutures @fundC, @NextDate, @Val output
end
end else begin
if @PhysEff = 0 begin
exec GetFundValueShortOnly_ZeroFutures @fundC, @NextDate, @Val output
end else begin
exec GetFundUnderlyingEffectiveValueShortOnly_ZeroFutures @fundC, @NextDate, @Val output
end
end
end
end
Set @Val = isnull(@Val,0)
if @Val <> 0
begin
insert into @TempValues (FundCode,EffectiveDate, Value) Values (@fundC,@NextDate, @Val)
end
if datepart(dw,@NextDate) = 7
begin
Set @NextDate = DATEADD(Day,2,@NextDate)
end
else
begin
if datepart(dw,@NextDate) = 6
begin
Set @NextDate = DATEADD(Day,3,@NextDate)
end
else
begin
Set @NextDate = DATEADD(Day,1,@NextDate)
end
end
end
delete #TableDates where FullDate = @NextDate
select @DateCounter = @DateCounter-1
end
Select * from @TempValues order by FundCode
drop table #TableDates
|
|
|
|
 |
And what is your question?
|
|
|
|
 |
Just a suggestion. Print the results from the following
insert into @fundcodestable
select pn, s
from StagedFundReportingData..FnxSplit('|', @fundcodes)
|
|
|
|
 |
Thank you Jschell, I managed to fix the problem.
|
|
|
|
 |
Hi,
I have a Oracle DB in which all the information is stored and this information is been consumed by different teams and below is the two options i have to decide on :
1. Write a Stored procedure and give the stored procedure to the respective teams and they can call the stored procedure.
2. Write a stored procedure wrap it as an API and expose the API, different team will call the API exposed and API will in turn hit the SP and return the response to the team.
Like to know what is the PRON and CRONS with these options and what is the best possible solution to go with.
Thanks
|
|
|
|
|
 |
We are working on separate computers in different locations so we are not connected to a network.
We are using SQL Server 2016 Express to develop a C# application in Visual Studio (college project).
My group mate sent me the (.bak) and (.mdf) files of the database he was working on so I can view it and make the necessary updates. I saw the data in the files after restoring and attaching them respectively. Some columns that were in (.bak)file were not in the (.mdf) file, and I need the (.mdf) file to be updated/contain the same data with the .bak file so I can add a datasource to the application for easy retrieval of data.
What could possibly have been the problem?
|
|
|
|
 |
kmllev wrote: What could possibly have been the problem? Could have been any one of a million things. Without much more information it is impossible to guess.
|
|
|
|
 |
kmllev wrote: What could possibly have been the problem? Are you sure the columns are in the .bak file?
Restore it to a new database, and make sure you have rights to write to the database; post any errors you see here
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
 |
How to speedup the execution of a query in Sql Server?
|
|
|
|
 |
In SSMS under tool the first entry is SQL Server Profiler - use that as your first step.
Never underestimate the power of human stupidity
RAH
|
|
|
|
 |
You need to present a bit more detail so that some suggestions can be given.
Generally, are you linking tables together ? How many? How many rows are in each table?
How many rows are being returned in your query?
With the SQL profiler you will be able to tell whether the server is scanning the table or seeking data via an index.
Your question is too vague to get a valuable answer.
|
|
|
|
 |
Hi David Mujica,
Thanks for your reply,but I need just rough idea or tips.
|
|
|
|
 |
My response was a tip, without more information we can't really be more specific. Statements like check you indexes (profiler helps) and check your syntax are going to be basically all we can do.
Tuning a DB and queries is almost an art so you need to give us some subject matter. What you have given us is like asking why your painting is rubbish!
Never underestimate the power of human stupidity
RAH
|
|
|
|
 |
After checking your keys and indexes, you could try to omit as much functions in the query as possible, limit the case-when switches and remove any unused tables and/or columns.
MSDN also has a few pages on the subject
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
 |
Hello there. I am trying to get data from 3 different tables based on simple join. One of the tables can have multiple values against one primary key. Here are the table designs
Table 1 - EmployeeDetails
EmployeeId INT, FirstName VARCHAR, SurName VARCHAR, SexId INT
Table 2 - EmployeeSex
SexId INT, Sex VARCHAR
Table 3 - EmployeeContacts
EmployeeId INT, Contact VARCHAR
I am using following query
SELECT ED.EmployeeId, ED.FirstName, ED.SurName, GROUP_CONCAT(EC.Contact)
FROM EmployeeDetails ED, EmployeeSex ES, EmployeeContacts EC
WHERE ED.SexId = ES.SexId AND ED.EmployeeId = EC.EmployeeId AND ED.EmployeeId = 'emp_password';
Now this query works fine if we have at least one contact number. But if there are not contacts, then this results in empty set. What is wrong with this query ? How can I improve so that it works in all scenarios (regardless of number of contacts in EmployeeContacts table). Thanks for any input.
|
|
|
|
 |
Use joins, not a where condition
SELECT ED.EmployeeId, ED.FirstName, ED.SurName, GROUP_CONCAT(EC.Contact)
FROM EmployeeDetails ED
INNER JOIN EmployeeSex ES on ED.SexId = ES.SexId
LEFT JOIN EmployeeContacts EC on ED.EmployeeId = EC.EmployeeId
WHERE ED.EmployeeId = 'emp_password';
If there are instance where an employee does not have an assigned sex, change the INNER JOIN to a LEFT JOIN
=========================================================
I'm an optoholic - my glass is always half full of vodka.
=========================================================
|
|
|
|
 |
Hi.
I have to choose between MySQL and PostgreSQL. I like use MS SQL, but it expensive for the customer.
Database have about 100 tables with max. 200 thousands rows.
Front application is .NET (winform) ,dataset or entity framework.
It's critical application, reliability is required.
Please advice me.
Karol
|
|
|
|
 |
Member 9076609 wrote: It's critical application, reliability is required. Sounds like Oracle or SQL Server are the only two choices to consider.
|
|
|
|
|