|
Correct.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
|
I Have a MS SQL Store proc, which takes max value of a field from the table for a day ( That field has got date part )and adds 1 if it exists or creates new if it does not exists.
Logic is like this
select a = max ( ID) where ID like (20070321%) /*Denotes March 21 2007*/
if (a is null ) set 200703210001
else a = a+1
insert into table (ID,....) values (a,....)
I am getting primary key violation error occassionaly.
I would like to know, How the SQL Server handles concurrent request for executing storedprocedures.
For example if it is sequential my logic should work fine
else
There can be duplicate values for ID fields.
Please help.
I knew it would end badly when I first met Chris in a Canberra alleyway and he said 'try some - it won't hurt you'..... - Christian Graus on Code Project outages
|
|
|
|
|
If this is in SQL Server 2005, you can wrap it inside a TRY/CATCH block.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi,
Thanks for the reply.
It is SQL 2000 / 7.0
Any other optimal solution
A moment of silence please. A programmer's best friend has passed beyond that great exception in the sky.... - Mark Conger on "The coffee machine has died"
|
|
|
|
|
Well, you could always try something like this:
insert into table1(...)
select @id, @col2, @col3
from table1 where not exists (select id from table1 where id = @id)
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi,
Personally, in this case I'd use an Identity column for the primary key, and put the date information in another column defaulted to get the date (DEFAULT GETDATE()). I'm not sure what having the date as part of the primary key is buying you.
Scot
|
|
|
|
|
How can i insert the char " ' " into my sql Statement so that the SQL server 2000 take it by using VB.net 2005
|
|
|
|
|
Replace ' with ''
str.replace("'","''");
|
|
|
|
|
WARNING: The original question could be a symptom of a security hole.
|
|
|
|
|
Thanx it solved the problem
|
|
|
|
|
Be very careful with his solution at it can hide security problems. It you want to reduce the risk of your database being attacked then I suggest you don't use that solution.
|
|
|
|
|
Colin Angus Mackay wrote: Be very careful with his solution at it can hide security problems.
Could you please explain this in detail ? I am not getting the problem about converting ' to ''
|
|
|
|
|
|
Pete O`Hanlon wrote: Colin wrote this article
Thanks for the plug.
|
|
|
|
|
Use parameterised queries.
For example:
INSERT INTO MyTable(Column1, Column2) VALUES(@value1, @value2);
cmd.Parameters.Add("@value1", someValue)
cmd.Parameters.Add("@value2", someOtherValue)
cmd.ExecuteNonQuery()
|
|
|
|
|
is the Select Top functionality or an alternative available in sql server 2000?
if I have this data...
100
200
330
445
665
887
999
...I know I can achieve it by ordering it and then using the if value > ALL ... but what if it is a lot more complicated than this?
thanks
Visual Studio can't evaluate this, can you?
public object moo<br />
{<br />
__get { return moo; }<br />
__set { moo = value; }<br />
}
|
|
|
|
|
joon_ wrote: is the Select Top functionality or an alternative available in sql server 2000?
Yes.
|
|
|
|
|
Which is it?
SELECT TOP didn't exist before 2005, did it..?
Visual Studio can't evaluate this, can you?
public object moo<br />
{<br />
__get { return moo; }<br />
__set { moo = value; }<br />
}
|
|
|
|
|
joon_ wrote: SELECT TOP didn't exist before 2005, did it..?
Yes, it did. TOP was introduced in SQL Server 2000
|
|
|
|
|
I found my problem, it seems that Select TOP has changed it's capabilities a lot in 2005, and this was the issue. Thanks.
On a sidenote, I'm sorry for the poor quality of some of my posts, but I'm really just trying to learn and help people at the same time. Thank you for remaining professional and not just breaking down all of my ideas because you think I'm an idiot.
Visual Studio can't evaluate this, can you?
public object moo<br />
{<br />
__get { return moo; }<br />
__set { moo = value; }<br />
}
|
|
|
|
|
i am useing dbcomman connection to conect sql
when trying to connect through lan computer
show time out
hoe to over come
|
|
|
|
|
|
Increment the connection timeout of SQL server Connection properties.
Knock out 't' from can't,
You can if you think you can
|
|
|
|
|
use CommandTimeout property of dbCommand to increase timeout time
DbCommand cmd = new DbCommand();
cmd.CommandTimeout = 60; // 60 secs timeout
|
|
|
|