Click here to Skip to main content
16,007,472 members
Home / Discussions / Database
   

Database

 
QuestionIdentity_Column Pin
Member 111616253-Oct-16 19:43
Member 111616253-Oct-16 19:43 
AnswerRe: Identity_Column Pin
Chris Quinn3-Oct-16 23:11
Chris Quinn3-Oct-16 23:11 
AnswerRe: Identity_Column Pin
Swinkaran4-Oct-16 1:17
professionalSwinkaran4-Oct-16 1:17 
QuestionSQL Server Reporting Services Query to Get Stored Procedure Name for Shared Dataset Pin
David_4129-Sep-16 11:48
David_4129-Sep-16 11:48 
AnswerRe: SQL Server Reporting Services Query to Get Stored Procedure Name for Shared Dataset Pin
Mycroft Holmes29-Sep-16 12:43
professionalMycroft Holmes29-Sep-16 12:43 
GeneralRe: SQL Server Reporting Services Query to Get Stored Procedure Name for Shared Dataset Pin
David_4129-Sep-16 12:51
David_4129-Sep-16 12:51 
QuestionExecuting SSIS Package from C# Console App Pin
indian14328-Sep-16 4:51
indian14328-Sep-16 4:51 
AnswerRe: Executing SSIS Package from C# Console App - resolved Pin
indian14328-Sep-16 12:09
indian14328-Sep-16 12:09 
Question.mdb file problem Pin
Member 1275753624-Sep-16 6:19
Member 1275753624-Sep-16 6:19 
AnswerRe: .mdb file problem Pin
Mycroft Holmes24-Sep-16 14:49
professionalMycroft Holmes24-Sep-16 14:49 
GeneralRe: .mdb file problem Pin
Richard Deeming26-Sep-16 2:12
mveRichard Deeming26-Sep-16 2:12 
GeneralRe: .mdb file problem Pin
Mycroft Holmes26-Sep-16 12:33
professionalMycroft Holmes26-Sep-16 12:33 
AnswerRe: .mdb file problem Pin
Victor Nijegorodov25-Sep-16 3:31
Victor Nijegorodov25-Sep-16 3:31 
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 

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.