Click here to Skip to main content
15,885,365 members
Home / Discussions / Database
   

Database

 
QuestionHow to update Oracle DB from SQL server through link server? Pin
hmanhha22-Sep-16 20:20
hmanhha22-Sep-16 20:20 
AnswerRe: How to update Oracle DB from SQL server through link server? Pin
Richard MacCutchan22-Sep-16 20:53
mveRichard MacCutchan22-Sep-16 20:53 
GeneralRe: How to update Oracle DB from SQL server through link server? Pin
hmanhha22-Sep-16 21:28
hmanhha22-Sep-16 21:28 
GeneralRe: How to update Oracle DB from SQL server through link server? Pin
Richard MacCutchan22-Sep-16 21:30
mveRichard MacCutchan22-Sep-16 21:30 
GeneralRe: How to update Oracle DB from SQL server through link server? Pin
Mycroft Holmes22-Sep-16 21:33
professionalMycroft Holmes22-Sep-16 21:33 
GeneralRe: How to update Oracle DB from SQL server through link server? Pin
Jörgen Andersson22-Sep-16 21:38
professionalJörgen Andersson22-Sep-16 21:38 
AnswerRe: How to update Oracle DB from SQL server through link server? Pin
hmanhha25-Sep-16 21:25
hmanhha25-Sep-16 21:25 
QuestionSQL Server Stored Procedure - Wait for a Table to be Created Pin
David_4122-Sep-16 9:29
David_4122-Sep-16 9:29 
Hello all. I have the following Stored Procedure:

SQL
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:

SQL
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:

C#
private void ParseStartProcedure(string spText)
        {            
            spText = spText.Replace("\r", " ");            
            spText = spText.Replace("\t", " ");           
            spText = spText.Trim();

            // Take everything after the first "AS"
            string[] queryPieces = Regex.Split(spText.ToLower(), " as ");
            string[] queryLines = Regex.Split(queryPieces[1], "\n"); //split on the new line character

            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)
                    {
                        //TODO: Add more robust error handling to handle errors other than "Failed to drop, etc.
                        string message = ex.Message;
                    }
                }
            }            
        }


modified 22-Sep-16 19:41pm.

Question[Help] How to create database for control Process in manufacturing company Pin
VaTo Tran21-Sep-16 2:05
VaTo Tran21-Sep-16 2:05 
QuestionIssue on communicating data from two difference system with different names Pin
chaurasiashankar19-Sep-16 19:47
chaurasiashankar19-Sep-16 19:47 
AnswerRe: Issue on communicating data from two difference system with different names Pin
Mycroft Holmes19-Sep-16 20:17
professionalMycroft Holmes19-Sep-16 20:17 
AnswerRe: Issue on communicating data from two difference system with different names Pin
Jörgen Andersson19-Sep-16 20:17
professionalJörgen Andersson19-Sep-16 20:17 
QuestionMariaDB und Updates with select same table Pin
RMolino17-Sep-16 8:33
RMolino17-Sep-16 8:33 
AnswerRe: MariaDB und Updates with select same table Pin
Mycroft Holmes17-Sep-16 11:22
professionalMycroft Holmes17-Sep-16 11:22 
GeneralRe: MariaDB und Updates with select same table Pin
RMolino18-Sep-16 0:42
RMolino18-Sep-16 0:42 
QuestionMajor differences between sql server express and sql server localdb Pin
Tridip Bhattacharjee5-Sep-16 23:20
professionalTridip Bhattacharjee5-Sep-16 23:20 
AnswerRe: Major differences between sql server express and sql server localdb Pin
Eddy Vluggen6-Sep-16 0:29
professionalEddy Vluggen6-Sep-16 0:29 
QuestionSQL While loop Pin
Mphirana31-Aug-16 4:40
Mphirana31-Aug-16 4:40 
AnswerRe: SQL While loop Pin
Victor Nijegorodov31-Aug-16 21:57
Victor Nijegorodov31-Aug-16 21:57 
AnswerRe: SQL While loop Pin
jschell1-Sep-16 7:10
jschell1-Sep-16 7:10 
GeneralRe: SQL While loop Pin
Mphirana1-Sep-16 9:40
Mphirana1-Sep-16 9:40 
QuestionExposing API VS Stored Procedure Pin
Java Lead31-Aug-16 4:29
Java Lead31-Aug-16 4:29 
AnswerRe: Exposing API VS Stored Procedure Pin
Richard MacCutchan31-Aug-16 4:46
mveRichard MacCutchan31-Aug-16 4:46 
Question.mdf file not updated? Pin
kmllev26-Aug-16 16:59
kmllev26-Aug-16 16:59 
GeneralRe: .mdf file not updated? Pin
Richard MacCutchan26-Aug-16 21:07
mveRichard MacCutchan26-Aug-16 21:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.