|
try Googling and what problem are you facing bcz its not that much small topic that can be answered in a post.
Best Of Regards,
SOFTDEV
If you have knowledge, let others light their candles at it
|
|
|
|
|
That is a very large topic, you are not going to get an sensible answer in a forum post, as softie said try Google [^]as the first step in your research.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm having a tree structure using the Adjacency list model, having an ID and ParentID for every node in the tree.
I need to find the lowest common ancestor for two or more IDs.
Anyone that knows how to do this?
(I know how to do it with the path enumeration or nested set model, but that doesn't help me here)
|
|
|
|
|
Jörgen Andersson wrote: using the Adjacency list model
I'm curious, what is this?
What database are you using?
Does this model dictate the format of your keys?
I use the hierarchyid in SQL Server to store my structures. How you would achieve this is dependant on your data structure.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Adjacency_list[^] is what Joe Celko calls what probably is the most common representation of a tree in a database.
Where every node has an ID and also stores the id of its parent.
I'm using Oracle
|
|
|
|
|
Thank you, I'm sorry not to be able to help, I have not used Oracle in a decade or so.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I want to update the top row in a table. I'm trying to get this to work:
update top (1) mytable set myfield="test"
This does not seem to compile. We have Microsoft SQL Server 2000. How can I accomplish this?
|
|
|
|
|
AFAIK, the update statement does not support the TOP condition. Try something like this;
UPDATE dbo.myTable
SET myField = 'test'
WHERE myPrimaryKeyField = (SELECT TOP 1 myPrimaryKeyField FROM dbo.myTable) Hope this helps
I are Troll
|
|
|
|
|
You should have an ORDER BY clause on the subquery to determine the correct TOP 1.
|
|
|
|
|
A more efficient statement would be this.
update Table
set field = new_value
where PK = (select min(PK) from Table)
only two letters away from being an asset
|
|
|
|
|
The predicate "TOP 1" applies only to the SELECT statement, not the UPDATE statement.
In order to update just the first row in your table, your UPDATE statement will need to be
UPDATE mytable
SET myfield = "test"
WHERE ((SELECT TOP 1 myfield FROM mytable) = myfield);
(I've split the statement over several lines to improve readability).
|
|
|
|
|
Is there a way to do this:
@FirstId uniqueidentifier = NULL;
@SecondId uniqueidentifier = NULL;
SELECT ..
FROM ..
WHERE
IF(@FirstId IS NOT NULL)
BEGIN
FirstId = @FirstId
END
IF(@SecondId IS NOT NULL)
BEGIN
AND FirstId = @FirstId
END
Or a smarter way?
Thanks in advance!
|
|
|
|
|
Hi,
this is what I would try:
... WHERE (@FirstId=null OR FirstId=@FirstId) AND (@SecondId =null OR SecondId =@SecondId )
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
Local announcement (Antwerp region): Lange Wapper? Neen!
|
|
|
|
|
I dont want to include the Ids if they are null.
|
|
|
|
|
The suggestion given does exactly what you want it to do.
|
|
|
|
|
Hi ,
How can i break Fullname Into First And Last Name.
For instance there is a column with name "Mr James Smith" and i want to break this into 3 columns with Title, FirstName and LastName.
Thank You
|
|
|
|
|
|
Be carefull with those; some people have no title, but a compound First-name, or a surname that's made up out of multiple names. I'd check the first argument from the string against a known list of titles, just to see whether that part was included or whether it's a first name.
I are Troll
|
|
|
|
|
Given the various kinds of name people have in various parts of world, you can not be sure that your code will work fine. It will irritate one person with different kind of name.
Still, you can have something predefined like:
1. First two words will go in as first name.
2. Last word will be the Last name.
3. Rest can be treated as middle name.
Beware, Sean Claude Van Dam will be angry by this approach.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
d@nish wrote: Sean Claude Van Dam
Jean
|
|
|
|
|
J4amieC wrote: Jean
I think Sean is the Irish one
|
|
|
|
|
I wasn't sure about the spelling. Hence I checked in google and got the results. Although I did not bothered to look down the page.
It's not necessary to be so stupid, either, but people manage it. - Christian Graus, 2009 AD
|
|
|
|
|
I have a service that needs to log into an SQL 2008 Express Server. The account of the service is the local system account. When the service starts, it checks if the SQL server is running. If not, it starts it, and waits for the service status to become "Running". When that has happened, the service logs in using a SqlConnection object.
If the login is done too fast, the SQL server reports "Cannot open database XXX requested by login. The login failed.". This indicates that the security subsystem of the database server is not in a running/complete state. No, I can see now that the database has not yet become online. My current approach is to hammer the database 10 times with 1 second interval to wait for the connection to succeed. This is idiotic, and just begs for sh*t to happen.
Does anybody know a better way? This is driving me insane...
--
Kein Mitleid Für Die Mehrheit
modified on Friday, October 16, 2009 5:15 AM
|
|
|
|
|
Can you not make your service depend on the SQL 2008 Express Server?
Check out the Dependencies tab on the control panel/services/properties page.
|
|
|
|
|
I could if I wanted to, but it doesn't help. The problem is that once the SQL server is reporting to be started to the SCM, it still hasn't made all databases online yet (only the master database is available). That work progresses after the SCM has been signalled that the service is running.
I found the solution to be easier than I thought. All I have to do is to
SELECT COUNT(*) FROM sys.databases WHERE name=@database_name AND state_desc='online' and see if it returns 0 or 1. Once the database manager reports the database as online, it is possible to use the database.
--
Kein Mitleid Für Die Mehrheit
|
|
|
|