By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,954 Members | 1,592 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,954 IT Pros & Developers. It's quick & easy.

Using host_name(): Crossing my fingers...

P: n/a
I did this thing with host_name(). I'm hoping someone can tell me if
I'm gonna get into trouble with this scheme before it's too late...

I have maybe 75 users.
They all call on a table of appointments (many thousands) and I dump
the ones being viewed into a temp table named TaskTEMP.
I am using a custom function within a View to grab a bunch of rows in
one table and slap them into a single column on the records returned
by the view.
Here's where I'm concerned-
When I insert the records into the TempTable I insert the value
HOST_NAME() into every row of a column named myMachine.
So the row looks like:

TaskID aName myMachine
1234 Jim Smith Dell101
1235 Fran Jones Dell101
1235 Mary Cat Dell101

When I run the view, I get:

TaskID myNames
1234 Jim Smith
1235 Fran Jones, Mary Cat

What I'm concerned about is when user 2 is looking at the same record
at the same time and inserts the following into TaskTEMP:

1234 Jim Smith CompaqXYZ
1235 Fran Jones CompaqXYZ
1235 Mary Cat CompaqXYZ

I use the HOST_NAME()filter in the example below to deal with this so
that both user one and user two get what they want instead of:

TaskID myNames
1234 Jim Smith, Jim Smith
1235 Fran Jones, Mary Cat, Fran Jones, Mary Cat

It works great in testing. The obvious problem is if two users have
the same machine name, but in this installation business rules prevent
that.
I hope someone can either validate this approach or improve or trash
it before it gets too late with this project.
thanks.
lq

The view and function look looks like this:

SELECT TaskID, dbo.fn_myNameGroup(TaskID) AS myNames
FROM dbo.TaskTEMP
GROUP BY TaskIDID

The function looks like this:

CREATE function dbo.fn_myNameGroup(@TaskID as int) returns
nvarchar(500)
as
begin
declare @ret_value nvarchar(500)
SET @ret_value=''
Select @ret_value=@ret_value + '; ' + aName FROM TaskTEMP where
TaskID=@TaskID AND myMachine=HOST_NAME()
RETURN RIGHT(@ret_value,LEN(@ret_value)-2)
end
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <47**************************@posting.google.com >,
la*************@hotmail.com says...
I did this thing with host_name(). I'm hoping someone can tell me if
I'm gonna get into trouble with this scheme before it's too late...

I have maybe 75 users.
They all call on a table of appointments (many thousands) and I dump
the ones being viewed into a temp table named TaskTEMP.
I am using a custom function within a View to grab a bunch of rows in
one table and slap them into a single column on the records returned
by the view.
Here's where I'm concerned-
When I insert the records into the TempTable I insert the value
HOST_NAME() into every row of a column named myMachine.
So the row looks like:


Why do you care what machine they are at? Why not just return their
information using their logon ID (not a NT account, but you app should
have them logon (database table lookup) and then you don't have to do
any of that.

--
--
sp*********@rrohio.com
(Remove 999 to reply to me)
Jul 20 '05 #2

P: n/a
> I did this thing with host_name().

I normally use #temp tables.
The data in the table will be private to a each connection.

EG

CREATE TABLE #Temp( MyInfo VARCHAR(255))
GO

INSERT #Temp .....

Jul 20 '05 #3

P: n/a
Lauren Quantrell (la*************@hotmail.com) writes:
It works great in testing. The obvious problem is if two users have
the same machine name, but in this installation business rules prevent
that.
Maybe. Beware that host_name() is provided by the application, through
the connection string, and an application may not provide it all. Or
may provide bogus information.
CREATE function dbo.fn_myNameGroup(@TaskID as int) returns
nvarchar(500)
as
begin
declare @ret_value nvarchar(500)
SET @ret_value=''
Select @ret_value=@ret_value + '; ' + aName FROM TaskTEMP where
TaskID=@TaskID AND myMachine=HOST_NAME()
RETURN RIGHT(@ret_value,LEN(@ret_value)-2)
end


Beware that the result of this function is undefined. You may get
the desired result, but you may get something else. The only safe
way is to iterate over the data. See also
http://support.microsoft.com/default.aspx?scid=287515.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.