|
you can using isnull fungtion to check on null
isnull([FIELDNAME], @Original_FIELDNAME,FIELDNAME)
|
|
|
|
|
Hello!
I will like to know following in context of SQL Server 2005:
1. Is 1 SP executed as 1 transaction?
2. In case of BEGIN TRAN/TRY/CATCH blocks, what happens if the following scenario occurs:
create proc...
declare x....
BEGIN TRAN
BEGIN TRY
....
COMMIT TRAN
END TRY
BEGIN CATCH
....
ROLLBACK TRAN
END CATCH
....
<some exception="" occurs="" here="">
....
end
will the SP be rolled back till start? or just the part after END CATCH? or just the statement causing exception?
Tried playing with SP, but seriously confused myself!!!
If anyone could provide useful link related to the problem, it will be great! Tried googling but could'nt find anything useful.
Regards,
Adeel
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
|
|
|
|
|
It depends. If your procedure is called from w/in an existing transaction then commit/rollback will affect both the inner and outer transactions.
You could use @@TRANCOUNT to determine wither or not you need to rollback or commit.
<br />
BEGIN TRY<br />
<br />
IF @@TRANCOUNT = 1<br />
COMMIT TRANSACTION<br />
END TRY<br />
BEGIN CATCH<br />
IF @@TRANCOUNT > 0<br />
ROLLBACK TRANSACTION<br />
<br />
END CATCH<br />
<br />
This way if your stored proc is the outer transaction it will commit on no errors. Then if there is an error in a nested transaction that was rolled back you won't get an error trying to rollback.
Search google for: sql server nested transactions
You should get plenty of results explaining this topic.
|
|
|
|
|
Just a simple question: Will SP be rolledback if any of its statements fails?
Example:
create proc xyz
insert....
update....
insert....
update....
end
exec xyz
Will top 3 statements be rolled back if last update fails (no begin/end tran or try/catch involved)?
Regards,
Adeel
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
|
|
|
|
|
No, outside of a transaction each statement is considered its own transaction. If the last statement fails all the others before it will still be persisted.
|
|
|
|
|
I am an SQL newbee & not understanding the results I am getting from a seemingly simple query. The query itself is returning the correct result but taking far too long. So I ran Explain to see what was happening. Sure enough more data is being examined than expected. But I can't figure out why. I have tried reordering the joins, but get the same result. Perhaps someone could educate me why it is returning so much data.
Note: All ID's are integer types. The ID of the respective tables are the primary key and the ID's used in the Assemdata table are indexed. MySQL ver 5.x
select
assemdata.AssemNum
innerpack.Descrip
hanger.Descrip
from
hanger join innerpack join assemdata
where
assemdata.Assemnum >=60000 and assemdata.Assemnum <=60050
and assemdata.InnerPackTypeID = innerpack.InnerPackID
and assemdata.hangerID = hanger.HangerID
Explain Result:
ID select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE innerpack ALL PRIMARY (Null) (Null) (Null) 3 Using where
1 SIMPLE assemdata ALL (Null) (Null) (Null) (Null) 2798 Using where
1 SIMPLE hanger ALL PRIMARY (Null) (Null) (Null) 2 Using where
Query Result:
AssemNum Descrip Descrip
60001 None Sawtooth
60002 None Sawtooth
60003 None Sawtooth
...... 49 Rows of data.
Thanks for any suggestions!
|
|
|
|
|
Shouldn't you be inner joining on condition?
|
|
|
|
|
I have tried specifying the joins as "inner" - it made no difference.
(My understanding is that MySQL interperts a join as "inner" unless otherwise specified.)
I have also tried being specific on the join member i.e. join on hangerID.
Also made no difference.
Thanks!
|
|
|
|
|
Have you tried selecting from the smallest table first?
|
|
|
|
|
Yes - I have tried all combinations I could think of. The Explain output is identical no matter what order I use.
Frustrating!
Thanks
|
|
|
|
|
Hello Mr. Member 4723455,
I always think it's better to put relational condition in "ON" clause of JOIN.
You can try:
select assemdata.AssemNum,innerpack.Descrip,hanger.Descrip
from hanger
join assemdata on assemdata.hangerID = hanger.HangerID
join innerpack on assemdata.InnerPackTypeID = innerpack.InnerPackID
where assemdata.Assemnum >=60000 and assemdata.Assemnum <=60050
Bye, (sorry for my bad English)
|
|
|
|
|
Suppaman,
I have tried it both ways i.e. using "join on table1.id=table2.id" & using "where table1.id=table2.id".
The results from an Explain Select are identical. But I agree the on method is easier to read.
Thanks!
|
|
|
|
|
You can try using views:
first create a view to filter out elements of assemdata with Assemnum >=60000 and Assemnum <=60050 (50 elems) then join this view with the other two table. In this way the query plan should be different and the query execution faster (I think).
Bye ^__^
|
|
|
|
|
I am trying to run windows application against SQL Server 2000 and get error message dot net 2005 is developement environment
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Both app and SQL server are local
connection string is
""Data Source={m};Initial Catalog=dbname;Integrated Security = SSPI; Trusted_Connection=Yes;"
I have tried enabling TCPIP protocoll on 2005 server but it does not help.
Please help
Thanks
Manish
|
|
|
|
|
hrrty wrote: I am trying to run windows application against SQL Server 2000
hrrty wrote: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005
The error message says it all, your connection appears to think it should be connecting to SQL Server 2005.
You always pass failure on the way to success.
|
|
|
|
|
I have a column of telephone numbers that I am trying to get the most dialled number from. Can anyone help?
|
|
|
|
|
SELECT COUNT(*), TelephoneNumber
From MyTable
GROUP BY TelephoneNumber
You might want to put in an ORDER BY there too. If you are only interested in the highest value then:
SELECT TOP 1 COUNT(*), TelephoneNumber
From MyTable
GROUP BY TelephoneNumber
ORDER BY COUNT(*) DESC
|
|
|
|
|
What is the difference between Difference between Correlated and Simple Subqueries
|
|
|
|
|
.NET- India wrote: What is the difference between Difference between Correlated and Simple Subqueries
Have you not heard of a search engine[^]? I typed your question into Google and got plenty of results.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Please Friend dont give this type of answers. If you dont want to give me the annswer please dont give me but if you want to give me thnx
|
|
|
|
|
|
.NET- India wrote: Please Friend dont give this type of answers.
What do you mean? I gave you an answer to your question.
If you don't know how to use a search engine to find answers to questions, I suggest you read this article[^]. Being able to use a search engine is pretty much a prerequisite for being a developer, so I suggest you learn fast.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
hi
I am using sql 2000 as database and windows form done in c# as the interface
I am having some 8 stored procedures in the project all are working fine except 1
Error which i got is ("Incorrect Syntax near SP_drivers")
i have checked it in DB by inserting values its working fine
but through interface its giving error
Thanks in Advance
Dont Get Paid for the Hours you worked, Get Paid for the Work You Have Done in an Hour.
|
|
|
|
|
Without seeing your C# code, it's hard to say what the problem could actually be.
|
|
|
|
|
its a bog code from here just i am passing parameters
connection = new SqlConnection(sql);
command = new SqlCommand("SP_Driver_WMile_Desc", connection);
connection.Open();
if (availability == true)
command.Parameters.AddWithValue("@Mode", "U");
else
command.Parameters.AddWithValue("@Mode", "I");
command.Parameters.AddWithValue("@Rate_ID", selected_node_parent);
command.Parameters.AddWithValue("@Vehicle_ID", selected_node);
command.Parameters.AddWithValue("@Drv_rate_ID", selected_driverrate);
if (rbtnWaitingDriverprice.Checked == true)
command.Parameters.AddWithValue("@Driver_Round_Type", true);
else
command.Parameters.AddWithValue("@Driver_Round_Type", false);
if (cboxWaitingDriver.SelectedItem.ToString() == "Up")
command.Parameters.AddWithValue("@Driver_Rounding", true);
else
command.Parameters.AddWithValue("@Driver_Rounding", false);
if (txtWatingDriverNearest.Text == "")
txtWatingDriverNearest.Text = "0";
command.Parameters.AddWithValue("@Driver_Nearest", txtDrivertonearest.Text);
for (i = 1; i <= 10; i++)
{
if (Waiting_Driver_Gridview[0, i - 1].Value == "")
command.Parameters.AddWithValue("@Driver_Mile_Box_" + i.ToString(), 0.00);
else
command.Parameters.AddWithValue("@Driver_Mile_Box_" + i.ToString(), Convert.ToDouble(Waiting_Driver_Gridview[0, i - 1].Value));
}
for (i = 1; i <= 10; i++)
{
if (Waiting_Driver_Gridview[1, i - 1].Value == "")
command.Parameters.AddWithValue("@Driver_Charge_Box_" + i.ToString(), 0.00);
else
command.Parameters.AddWithValue("@Driver_Charge_Box_" + i.ToString(), Waiting_Driver_Gridview[1, i - 1].Value);
}
command.ExecuteNonQuery();
connection.Close();
MessageBox.Show("Data Added Successfully ", "Data Adition", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Dont Get Paid for the Hours you worked, Get Paid for the Work You Have Done in an Hour.
|
|
|
|