|
You were close. You need to reference the inital table in the subquery for it to work.
SELECT
Name,
(select name from employees where employeeid = e.reportsto) as 'ReportsTo'
from
employees e
Better set logic (should be faster on large tables):
SELECT
e1.Name,
e2.Name as ReportsTo
FROM
employees e1
LEFT JOIN
employees e2
ON (e1.reportsto = e2.employeeid)
|
|
|
|
|
Almost
Thanks Mike
|
|
|
|
|
Hi,
I have a table, userprofile(fname,lname,address,hobbies). Hobbies is multiple selection from the list box, which binds data at run time. I want to select multiple hobbies and insert it into one single row. I have a faint idea od using a for loop for this purpose. Can you please help me?
Regards,
Anuradha
|
|
|
|
|
What you should really do is normalise your db and have your tables like this
userprofile(UserID, fname,lname,address)
hobbies(UserID, Hobby)
|
|
|
|
|
First of all, thanks you for the prompt reply. I actually thought about this earlier- having a user table and a hobby table and another user_x_hobby table where I can insert the Userid against the HobbyId. But then my question was, what query I could run on this. I am new to .Net/SQL and trying to explore new possibilities.
Regards,
Anuradha
|
|
|
|
|
How do I use WebServices as a datasource for my reports? I see where you create a datasource there's an option for "xml". Has anyone used "WebService" to create a custom dataset data extension, and if so how do you do it?
|
|
|
|
|
|
hai to all,
Here i am trying to connect with the remote machine database.The db connection string has given in web.config file.(tried both with IP address and machine name for data source)
While i am debugging my application,it is giving an errore like
"sql server does not exist or access denied"
What is the solution to this problem???
Am i need to set any setting at any level???
give me sme solution.
kissy
|
|
|
|
|
Is there Database in the new machine ...... if so check whether u gave the correct user name and password to the DB
If U Get Errors U Will Learn
If U Don't Get Errors U Have Learnt
|
|
|
|
|
thanks for responding to my post.
Yes the remote machine have the db and i have checked for all the parameters in the connection string which are correct.
<add key="connstring" value="Data Source=104.131.2.91;initial catalog=batch;uid=bt1;pwd=bt201;persist security info=false">
still i am unable to connect to the database.
i am using vs2003 and sqlserver 2000
kissy
|
|
|
|
|
Kissy16 wrote: "sql server does not exist or access denied"
Remote Server May be down or the Sql Server service may be stopped...
Regards J O H N
"Even eagles need a push." David McNally
|
|
|
|
|
wat abt this sqlserver service???
here sql server for remote machine is not down,i am sure for this.
can u plz give me some solution???
thanks for ur answer
kissy
|
|
|
|
|
Kissy16 wrote: tried both with IP address and machine name for data source
If you are facing connectivity issues after ensuring that the SqlServer service is started, probably you might want to take a look at the following factors
1) I've noticed that the datasource taking params like ipaddress/SqlServer2000 (read it as ipaddress slash sqlserver2000) or
machinename/SqlServer2000 (assuming that in both cases you are having SqlServer 2000)
2) If you are using SqlServer2000 and if you have tried the above mentioned option and still experiencing connectivity issues, probably resetting protocols using "sql server client network utility", try disabling and re-enabling TCP/IP and Named Pipes.
-- modified at 8:00 Thursday 6th September, 2007
|
|
|
|
|
Suppose I have the following stored procedure
CREATE PROCEDURE dbo.GetContacts
AS
SELECT ContactID, ContactName FROM Contacts
GO
Then I can execute the stored procedure as follows:
EXEC dbo.GetContacts
How can I receive the returned results into a temporary or permanent table?
|
|
|
|
|
John Gathogo wrote: SELECT ContactID, ContactName FROM Contacts
John Gathogo wrote: How can I receive the returned results into a temporary or permanent table?
Using Into Clause
Into Temporary Table
----------------------
SELECT ContactID, ContactName INTO #TempTable FROM Contacts
The above sql stmt will create a temporary table and Inserts the resulting rows from the query into it.
Into Permanent Table
----------------------
Insert Into PermanentTable(ContactID, ContactName)(SELECT ContactID, ContactName FROM Contacts)
this statement Inserts the resulting rows from the select query into permanent table provide both the tables should have the same definition.
Regards J O H N
"Even eagles need a push." David McNally
|
|
|
|
|
Actually what I meant is that I want to use the stored procedure to populate the table. I already found a way:
CREATE @TmpTable (ContactID INT, ContactName NVARCHAR(36))
INSERT INTO @TmpTable EXEC dbo.GetContacts
SELECT * FROM @TmpTable
Thanks all the same.
|
|
|
|
|
<br />
CREATE TABLE #TEMP (ContactID int, ContactName varchar(50))<br />
<br />
INSERT #TEMP<br />
EXEC dbo.GetContacts<br />
<br />
SELECT * FROM #TEMP<br />
<br />
|
|
|
|
|
create Function [dbo].[MyFun] ()
Returns @tbl table (id int,Item varchar(100))
as
begin
insert into @tbl
SELECT ContactID, ContactName FROM Contacts
return
End
then use this
insert into temporary table/permanent table
select * from MyFun()
Manu
|
|
|
|
|
Hi,
This is closely related to my previous question BUT ...
I go through a web log file and extract each line and put the data into a new row in a datatable.
I then change the data in one field of each row.
I then use that datatable as my source for extracting various statistics.
At no time do I really need to save the datatable to the underlying database as far as I can see.
If I don't need to save the datatable to the database, do I really need to do a datatable.update let alone a dataset.acceptchanges?
Glen Harvy
|
|
|
|
|
If you only need to use the DataTable object as an in-memory repository for data, then you don't need to use these methods. They are used for synchronising the contents of the DataTable with an underlying database.
Paul
|
|
|
|
|
Thanks for that - it's funny how I have never stopped to think about what I was doing until performance became an issue. Suppose this is often the case now that I think about it.
Just one thing more though...
Is there any need at all to call dataset.acceptchanges() if you have just done a datatable.update and you know there hasn't been any other changes to the datatset.
Logically the answer is no but I just want to confirm that.
Thanks for your time.
Glen Harvy
|
|
|
|
|
I don't do this kind of stuff with DataTables very often, but according to the MSDN documentation...
When AcceptChanges is called, any DataRow object still in edit mode successfully ends its edits. The DataRowState also changes: all Added and Modified rows become Unchanged, and Deleted rows are removed.
So I think you should call AcceptChanges after Update to reset the status of the rows in your DataTable.
Paul
|
|
|
|
|
Yep - I agree with you.
Thanks.
Glen Harvy
|
|
|
|
|
Hi,
I have developed the habit of coding new rows etc as follows:
DataRow nr = DataSet.Tables[logName].NewRow();
nr["c-ip"] = appField[0].ToString();
nr["cs-username"] = appField[2].ToString();
this.DataSet.Tables[logName].Rows.Add(nr);
this.TableAdapter.Update(DataSet.log1);
DataSet.AcceptChanges();
Performance has raised it's head and I am wondering now why I am calling DataSet.AcceptCahges() .
Is this necessary in this instance?
Does AcceptChanges actually do anything?
Glen Harvy
|
|
|
|
|
Whilst analysing one of my stored procedures, I was curious on investigating whether there are any associated (latent/deliberate) pitfalls associated with respect to RECURSIVE Stored Procedure. From my side, I have ensured the following:
1) Currently, I have as much fine drilled the WHERE clause so that as narrowed down records as minimal are only selected for delete operation.
2) No Temp Tables have been used to prevent any deadlock even whilst entering into them.
3) From my personal preference, CURSORS are a big no-no considering the huge performance and penalty that we ought to pay for through our nose.
Should I consider any more option to ensure that it does not penalize my database for any performance issues?
|
|
|
|