Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

Friday, March 30, 2012

predict products ( data mining 2000)

i want to make a web page and when somebody come in. i want show for him which products that everyone often buy at that time ( month or summer ).

how i do in data mining to predict that products ?

more: i want know how much percent of product is like by buyer

or i want show products with desc % of the like of people

You can use Microsoft Association Rules to resolve this problem: you can include the time info (such as month or summer) in each trasaction, our Assocation Rules will do the counting and find any rules apply. Please check the live sample http://www.sqlserverdatamining.com/DMCommunity/LiveSamples/54.aspx on about the train Association Rules. You might also want to check out the tips and tricks on our data mining web site http://www.sqlserverdatamining.com. SQL Server books online is another resouce you can use to learn about SQL Server in general and SQL Server Data Mining.

Besides time info, you can also include basket info (other products the user has already chosen) and the user's demographic info(such as Geneder, Income --if you have those info) in your model.

DMX is the langue you can use to do prediction. The function PredictHistogram(Product) will given the list of products and their probability when you run queries against your model.

Good luck,

|||

For SQL Server 2000 you would use Microsoft_Decision_Trees. You will build a model based on your customer/shopping basket table using the wizard. Since 2000 doesn't support creating nested tables in the wizard, you then need to add the nested table from your transaction table in the data mining editor.

Your model will look something like this

CREATE MINING MODEL MyModel
(
BasketID LONG KEY,
Season TEXT DISCRETE
Products TABLE PREDICT
(
ProductName TEXT KEY
)
) USING Microsoft_Decision_Tree

If you have a large number of products (which you likely do) you will have to set the MAXIMUM_INPUT_ATTRIBUTES and MAXIMUM_OUTPUT_ATTRIBUTES on the model as well, otherwise the algorithm will perform feature selection to the default 255.

|||Thanks.sql

predict products ( data mining 2000)

i want to make a web page and when somebody come in. i want show for him which products that everyone often buy at that time ( month or summer ).

how i do in data mining to predict that products ?

more: i want know how much percent of product is like by buyer

or i want show products with desc % of the like of people

You can use Microsoft Association Rules to resolve this problem: you can include the time info (such as month or summer) in each trasaction, our Assocation Rules will do the counting and find any rules apply. Please check the live sample http://www.sqlserverdatamining.com/DMCommunity/LiveSamples/54.aspx on about the train Association Rules. You might also want to check out the tips and tricks on our data mining web site http://www.sqlserverdatamining.com. SQL Server books online is another resouce you can use to learn about SQL Server in general and SQL Server Data Mining.

Besides time info, you can also include basket info (other products the user has already chosen) and the user's demographic info(such as Geneder, Income --if you have those info) in your model.

DMX is the langue you can use to do prediction. The function PredictHistogram(Product) will given the list of products and their probability when you run queries against your model.

Good luck,

|||

For SQL Server 2000 you would use Microsoft_Decision_Trees. You will build a model based on your customer/shopping basket table using the wizard. Since 2000 doesn't support creating nested tables in the wizard, you then need to add the nested table from your transaction table in the data mining editor.

Your model will look something like this

CREATE MINING MODEL MyModel
(
BasketID LONG KEY,
Season TEXT DISCRETE
Products TABLE PREDICT
(
ProductName TEXT KEY
)
) USING Microsoft_Decision_Tree

If you have a large number of products (which you likely do) you will have to set the MAXIMUM_INPUT_ATTRIBUTES and MAXIMUM_OUTPUT_ATTRIBUTES on the model as well, otherwise the algorithm will perform feature selection to the default 255.

|||Thanks.

Predict % completed

I'm doing a web search page on a db that has about 1 million records, and
the query is quite complicated. I would like to provide the user some
feedback will the db server is performing the search.
What is the best way to do this? any examples or tutorials?
The only way I can think of is doing 10000 records at a time and add 1% to a
counter.
There must be a better way.
Any input is greatly appreciated,
AaronWhat about firing first the Query to the Optimizer and sshowing the
execution plan for it, you might see there how long (CPU cycles) it will
last and how many rows are estimated (Requirement of maintained statistics
:-)
See for this one:
USE NORTHWIND
GO
SET SHOWPLAN_ALL ON
GO
Select CompanyName from Customers where CompanyName LIKE '%A%'
GO
SET SHOWPLAN_ALL OFF
GO
(Result gonna spread over the page, best thing you execute in on your own.)
HTH, Jens Smeyer
http://www.sqlserver2005.de
--
"Aaron" <kuya789@.yahoo.com> schrieb im Newsbeitrag
news:O503JyYQFHA.204@.TK2MSFTNGP15.phx.gbl...
> I'm doing a web search page on a db that has about 1 million records, and
> the query is quite complicated. I would like to provide the user some
> feedback will the db server is performing the search.
> What is the best way to do this? any examples or tutorials?
> The only way I can think of is doing 10000 records at a time and add 1% to
> a counter.
> There must be a better way.
> Any input is greatly appreciated,
> Aaron
>
>|||what's the Optimizer ? is that an addon to sql server?
i don't think i have that
"Jens Smeyer" <Jens@.Remove_this_For_Contacting.sqlserver2005.de> wrote in
message news:eu5VT4YQFHA.1392@.TK2MSFTNGP10.phx.gbl...
> What about firing first the Query to the Optimizer and sshowing the
> execution plan for it, you might see there how long (CPU cycles) it will
> last and how many rows are estimated (Requirement of maintained statistics
> :-)
> See for this one:
>
> USE NORTHWIND
> GO
> SET SHOWPLAN_ALL ON
> GO
> Select CompanyName from Customers where CompanyName LIKE '%A%'
> GO
> SET SHOWPLAN_ALL OFF
> GO
> (Result gonna spread over the page, best thing you execute in on your
> own.)
> HTH, Jens Smeyer
>
> --
> http://www.sqlserver2005.de
> --
> "Aaron" <kuya789@.yahoo.com> schrieb im Newsbeitrag
> news:O503JyYQFHA.204@.TK2MSFTNGP15.phx.gbl...
>|||On Fri, 15 Apr 2005 16:06:44 -0700, Aaron wrote:

>what's the Optimizer ? is that an addon to sql server?
>i don't think i have that
(snip)
Hi Aaron,
The optimizer is an integral part of SQL Server. It's the part of the
server that reviews your query and determines the execution plan (the
order and methods in which data will be fetched and combined to satisfy
your request).
Best, Hugo
--
(Remove _NO_ and _SPAM_ to get my e-mail address)

Monday, March 26, 2012

Powershell?

Hi,
Do any folk here use SMO from PowerShell?

I've found a limited number of web postings about the subject, but not much newsgroup/forum chat.

Specifically, I'm wondering how to capture exceptions raised by SMO calls.
For example, I wanted to drop all logins on a server, so thought I'd try this:
$sql = new-object 'microsoft.sqlserver.management.smo.server' 'servername'
$sql.Logins | %{$_.Drop()}
which throws this error for every login:
Exception calling "Drop" with "0" argument(s): "Drop failed for Login 'BloggsJ'. "
At line:1 char:24
+ $sql.Logins | %{$_.drop( <<<< )}

Is there more information to be had? I've tried defining an object as microsoft.sqlserver.management.smo.smoexception but I'm not quite sure what to do with it...

TIA,
Robin.

Do a search on the web for "PowerSMO" and you will find a number of tutorials I wrote on using SMO and PowerShell.

Dan

Friday, March 23, 2012

Pound Sign Problem

Hi

I have come across a bit of problem with my Web Form. I have standard textbox which inserts a value into a SQL 2000 database. However if I put a pound sign anywhere inside the text box and do the insert it disappears when I try and reshow the value.

I have checked the database field to see if it has been inputted but its no where to be seen.

So what has happened to my pound sign? any ideas?

I am using VS.Net 2003.

Thanks in advanceThat is strange. SQL 2000 does not reject the pound sign. Neither does the text box control. I did several tests, cannot seem to produce your problem. Do you do any kind of massage to your input in your code before it is insert into the database table?

Please post your code.|||Hiya

Sorry for the delay in getting back to you, please find below my code. This problem really does have me miffed

Cmd As New SqlCommand

Conn.Open()
With objCmd
.Connection = Conn
.CommandType = CommandType.Text
.CommandText = "INSERT INTO PhoneList (FirstName, Surname) " & _
" VALUES (@.FirstName, @.Surname)"

.Parameters.Clear()
.Parameters.Add("@.FirstName", SqlDbType.VarChar).Value = txtFirstName.Text
.Parameters.Add("@.Surname", SqlDbType.VarChar).Value = txtSurname.Text
.ExecuteNonQuery()
End With
Conn.Close()

Field types in theSQL Server 2000 DB are Varchar's. Just thought could this be one of the rasons for the roblem

Thanks in advance|||I have seen this problem before and I think the DataType on the column needs to beText to store ASCII characters.|||Hi PD

I have changed the data type to Text in my SQL DB but I still get the same problem

It just seems really odd, every other character works including !"$%^&*()

but the £ just does not get stored|||I was sleeping when I read your post, I thought you meant the # sign.

Themonetary data types MONEY and SMALLMONEY can accept many national currency symbols like the British pound, the Euro and others.|||How about if you use NVarChar instead?
Although you shouldn't have to go unicode in order to save the pound sign...

Regards
Fredrik|||Hi Fredrik

I have tried changing it to NvarChar and still didnt have any joy. I have even searched around on teh web and cant seem to find anybody else who has had that problem

Just wondering can anybody else replicate this problem there end?

I dont seem to have any hair left..... i think ive pulled it all out|||OK the only way I can seem to get round the problem is by inputting the HTML equvilant of a £ sign which is £

So when this is rendered it appears as a £

But im sure this cant be a solution.... can it?

I even tried to set validateRequest="false", but did not have any joy|||I am sorry. I thought it was # as well.
I did a test. Cannot re-produce the problem. I am using Varchar for the data field.

Did you try to debug and see whether the pound value was passed in correctly?|||Here is my test code in C#. I just have a textbox at the front end.


conn.Open ();
string strInsert = "Insert Into Chun (Test) Values (@.chun)";
SqlCommand cmd = new SqlCommand (strInsert, conn);
SqlParameter p = new SqlParameter("@.chun",SqlDbType.VarChar,50);
p.Value = txtPound.Text;
p.Direction = ParameterDirection.Input;
cmd.Parameters.Add (p);
cmd.ExecuteNonQuery ();
conn.Close ();

Here is the value I entered in the text box:

£5432

The value is stored and retrieve displayed as it is.|||I have a similar issue when I pass the # as part of a query string! It chops everything off after the pound sign!|||I did eventually manage to solve my pound sign problem, it was a problem with the globalization setting in the web.config.

Try reading the below article and see if it helps

http://www.howtodothings.com/showarticle.asp?article=755

Good luck

Wednesday, March 21, 2012

Post XML Data with SQLServer

Hi,
I want to "post" Data in XML Format to a web server with SQL Server 2000.
How can I do that?
Hi
Depending on what exaclty is required then take a look at the following and
other articles on the site:
http://sqlxml.org/faqs.aspx?faq=15
John
"Mehmet" <Mehmet@.discussions.microsoft.com> wrote in message
news:178F3F0E-42CF-41B1-9C30-45C8CD51C851@.microsoft.com...
> Hi,
> I want to "post" Data in XML Format to a web server with SQL Server 2000.
> How can I do that?
|||Hi,
First of all thanks.But I want to post xml data with a SQLServerAgent-Job to a web server or url.
|||Hi
If you are using an agent job, the I would expect you to be writing to XML
files. Try: http://sqlxml.org/faqs.aspx?faq=10
John
"Mehmet" <Mehmet@.discussions.microsoft.com> wrote in message
news:799D9529-78EA-445A-BC7E-16EDD100C56E@.microsoft.com...
> Hi,
> First of all thanks.But I want to post xml data with a SQLServerAgent-Job
to a web server or url.

Monday, March 12, 2012

Possible use or import a MySQL database in SQL Server 2005?

Hi all,
I am developing a web application and the back end is MySQL database.

Now I want to shift all the data to SQL Server 2005.

Is there any method to do it?

Thanks

Tomy

Hi,

You can try to use SQL Server Integration Services to do the import/export. Please check the following link for more information

http://msdn2.microsoft.com/en-us/library/ms141026.aspx

HTH. If this does not answer your question, please feel free to mark the post as Not Answered and reply. Thank you!

Possible to send parameter to Excel (via Web) to pas along through to SQL Server?

Is there anyway to pass a parameter to an Excel spreadsheet (loaded in a browser) to use as a parameter in SQL statement?

I know that the Microsoft Technologies can write Excel files and then load them, but I'm looking to take an existing workbook, parameterize the SQL statement and pass parameters via the Querystring/Form Post to it.

Why you may ask? For existing PivotTables/Charts that can be filtered BEFORE they are run.

Any/all thoughts appreciated.

BobYeah, there's a lot you can do. Check out this KB article for some ideas and code:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;316934|||What I'm looking to do specifically is to have a "template" of a workbook that I will pass connection/SQL Query information to, to be displayed on the fly.

Example:
A Pivot Table show results of: SELECT * FROM Products WHERE ProductID = <parameter
Web page passes a ProductID and the query is run (with the filter).

I'm assuming that I will have some sort of VBA code to hold the CORE query and I would like to be able to pass the parameter via ASP.

Any additional thoughts?

Thanx,
Bob|||Ok, I think I understand what you're trying to do. I believe this article shows you how (see the Generate XML from a Dataset for use in Excel 2003 section):

http://msdn.microsoft.com/office/understanding/excel/technicalarticles/default.aspx?pull=/library/en-us/odc_xl2003_ta/html/odc_xltransferxmltoxlwvb.asp

Friday, March 9, 2012

Possible to OPENXML() from URL?

Is it possible to get the XML Document for a call to OPENXML() from a URL
directly?
Example: I have a .NET web service that returns XML based on parameters
submitted to the URL. I'd like to be able to write a TSQL batch that gets
XML documents from this server and processes them using OPENXML to update
rows in a SQL table.
Anyone ever done something like this?
TIA
Paul
Have you considered using an XML template? Templates accept parameters, much in the same way as stored procedures.
I've written an article on this topic, which you can find at the following URL:
http://www.sqljunkies.com/Article/53...3C8ECACDC.scuk
Hope this helps!
Denise.
Denise E. White
Technical Director
The Next Version UK
www.thenextversion.com
www.denisewhite.co.uk

Possible to make RS part of a failover Cluster? SQL 2000

Hi,
I am not able to install Reporting Services (RS) on a Web Farm, but would
like to get it installed and configured on a active/passive Failover Cluster.
What do you think about the following scenario?
1. Install RS on one server and create the databases on the SQL Server
Cluster.
2. Install RS on the second server.
3. Configure the second RS to use the clustered database.
4. Copy the encryption key from the RS installation that created the
databases.
5. Apply the encryption key to the RS installation that did not create the
database.
6. Create RS service as a generic service for the Cluster.
I have not tested this yet, but in theory it should work or?
That may work, but I would not recommend it. I certainly wouldn't try it.
The reason you run SQL Server in a cluster is for high availability. Mixing
your IIS and RS with the SQL Server cluster seems to compromise high
availability, if not defeat the purpose. You may find money well spent on a
separate RS box or two, considering potential support and maintenance
headache you may have otherwise.
Linchi
"Nina" <Nina@.discussions.microsoft.com> wrote in message
news:092B2EBC-3769-4F94-B12F-6CCAEF70B6EC@.microsoft.com...
> Hi,
> I am not able to install Reporting Services (RS) on a Web Farm, but would
> like to get it installed and configured on a active/passive Failover
> Cluster.
> What do you think about the following scenario?
> 1. Install RS on one server and create the databases on the SQL Server
> Cluster.
> 2. Install RS on the second server.
> 3. Configure the second RS to use the clustered database.
> 4. Copy the encryption key from the RS installation that created the
> databases.
> 5. Apply the encryption key to the RS installation that did not create the
> database.
> 6. Create RS service as a generic service for the Cluster.
>
> I have not tested this yet, but in theory it should work or?
|||Thanks Linchi,
I have been doing some more reading. And it seems like some people have made
it “kind of work” , but there is no “One Documentation” on this. And the
information I find is a bit questionable.. and like you say, it can cause
some serious headaches…
I also read that making configuring RS as part of a failover cluster is not
supported by Microsoft. They even do not recommend to make IIS part of a
failover cluster.
I understand that buying one new server or two is ok, but not when you have
four environments, and each would need at least one.
Need to have a think about this one..
Nina
"Linchi Shea" wrote:

> That may work, but I would not recommend it. I certainly wouldn't try it.
> The reason you run SQL Server in a cluster is for high availability. Mixing
> your IIS and RS with the SQL Server cluster seems to compromise high
> availability, if not defeat the purpose. You may find money well spent on a
> separate RS box or two, considering potential support and maintenance
> headache you may have otherwise.
> Linchi
> "Nina" <Nina@.discussions.microsoft.com> wrote in message
> news:092B2EBC-3769-4F94-B12F-6CCAEF70B6EC@.microsoft.com...
>
>
|||If you ever test it or find another solution, could you kindly share it with the world?
************************************************** ********************
Sent via Fuzzy Software @. http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...

Possible to lock a row within a stored procedure in SQL Server 2000?

Hi All,

I have a table that holds pregenerated member IDs.

This table is used to assign an available member id to web site
visitors who choose to register with the site

So, conceptually the process has been, from the site (in ASP), to:

- select the top record from the members table where the assigned flag
= 0

- update the row with details about the new member and change the
assigned flag to 1

- return the selected member id to the web page

Now I'm dealing with the idea that there may be brief, high traffic
periods of registration, so I'm trying to build a method (stored
procedure?) that will ensure the same member id isn't returned by the
select statement if more than 1 request to register happens at the
same instant.

So, my question is, is there a way, once a record has been selected,
to exclude that record from other select requests, within the bounds
of a stored procedure?

ie:

- select statement is executed and row is instantly locked; any other
select statement running at that exact moment will receive a different
row returned and sill similarly lock it, ad nauseum for as many
simultaneous select statements as take place
- row is updated with details and flag is updated to indicate the
member id is no longer unassigned
- row is released for general purposes etc

If what I'm suggesting above isn't practical, can anyone help me
identify a different way of achieving the same result?

Any help immensely, immensely appreciated!

Much warmth,

MurrayM Wells <planetquirky@.planetthoughtful.org> wrote in message news:<j1o220p3uauokindou45q9l305eq8au783@.4ax.com>...
> Hi All,
> I have a table that holds pregenerated member IDs.
> This table is used to assign an available member id to web site
> visitors who choose to register with the site
> So, conceptually the process has been, from the site (in ASP), to:
> - select the top record from the members table where the assigned flag
> = 0
> - update the row with details about the new member and change the
> assigned flag to 1
> - return the selected member id to the web page
> Now I'm dealing with the idea that there may be brief, high traffic
> periods of registration, so I'm trying to build a method (stored
> procedure?) that will ensure the same member id isn't returned by the
> select statement if more than 1 request to register happens at the
> same instant.
> So, my question is, is there a way, once a record has been selected,
> to exclude that record from other select requests, within the bounds
> of a stored procedure?
> ie:
> - select statement is executed and row is instantly locked; any other
> select statement running at that exact moment will receive a different
> row returned and sill similarly lock it, ad nauseum for as many
> simultaneous select statements as take place
> - row is updated with details and flag is updated to indicate the
> member id is no longer unassigned
> - row is released for general purposes etc
> If what I'm suggesting above isn't practical, can anyone help me
> identify a different way of achieving the same result?
> Any help immensely, immensely appreciated!
> Much warmth,
> Murray

It's not clear from your description why you need to generate the IDs
in advance - a simpler approach might be to use an IDENTITY column,
and insert directly into the members table for a new registration. You
can then return the system-generated value to the client using
scope_identity(). This assumes, of course, that the membership ID is
simply a number, with no other meaning:

create table dbo.Members (
MemberID int identity(1,1) primary key,
FirstName varchar(50) not null,
LastName varchar(50) not null
)
go

insert into dbo.Members (FirstName, LastName)
values ('Murray', 'Wells')

select 'Your ID is: ' + cast(scope_identity() as char(2))
go

If you do need some control over the value of the membership ID, then
one of these approaches might be suitable:

http://groups.google.com/groups?q=s...uewin.ch&rnum=1

If this doesn't help, you may want to post the structure (CREATE
TABLE) of your members table, along with some sample data, and explain
exactly what you want to return to the client.

Simon|||On 4 Feb 2004 23:44:05 -0800, sql@.hayes.ch (Simon Hayes) wrote:

>M Wells <planetquirky@.planetthoughtful.org> wrote in message news:<j1o220p3uauokindou45q9l305eq8au783@.4ax.com>...
>> Hi All,
>>
[ here there be snippage ]

>It's not clear from your description why you need to generate the IDs
>in advance - a simpler approach might be to use an IDENTITY column,
>and insert directly into the members table for a new registration. You
>can then return the system-generated value to the client using
>scope_identity(). This assumes, of course, that the membership ID is
>simply a number, with no other meaning:
>create table dbo.Members (
>MemberID int identity(1,1) primary key,
>FirstName varchar(50) not null,
>LastName varchar(50) not null
>)
>go
>insert into dbo.Members (FirstName, LastName)
>values ('Murray', 'Wells')
>select 'Your ID is: ' + cast(scope_identity() as char(2))
>go
>If you do need some control over the value of the membership ID, then
>one of these approaches might be suitable:
>http://groups.google.com/groups?q=s...uewin.ch&rnum=1
>If this doesn't help, you may want to post the structure (CREATE
>TABLE) of your members table, along with some sample data, and explain
>exactly what you want to return to the client.

Hi Simon,

Thank you very much for your help with this!

Unfortunately, the need to use pre-generated member ids is a foregone
issue; it's not something I have any control over.

I looked at the two examples in the link you provided. The first makes
sense to me, but I can't formulate a query that makes it do exactly
what I want. And I don't yet know enough about locking in SQL Server
to know if the locking hint (UPDLOCK) does what I hope it will do.

To give you a little extra detail, my test table definition is:

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[tblmembers]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[tblmembers]
GO

CREATE TABLE [dbo].[tblmembers] (
[recid] [int] IDENTITY (1, 1) NOT NULL ,
[memid] [numeric](18, 0) NULL ,
[memname] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
NULL ,
[mememail] [varchar] (255) COLLATE
SQL_Latin1_General_CP1_CI_AS NULL ,
[activated] [bit] NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[tblmembers] WITH NOCHECK ADD
CONSTRAINT [PK_tblmembers] PRIMARY KEY CLUSTERED
(
[recid]
) ON [PRIMARY]
GO

CREATE UNIQUE INDEX [IX_tblmembers_memid] ON
[dbo].[tblmembers]([memid]) ON [PRIMARY]
GO

INSERT tblmembers(recid,memid,memname,mememail,activated)
VALUES('1','1000001','John Smith','john@.smith.com','1')
INSERT tblmembers(recid,memid,memname,mememail,activated)
VALUES('2','1000002','Jen Smith','smith@.jen.com','1')
INSERT tblmembers(recid,memid,memname,mememail,activated)
VALUES('3','1000003','','','0')
INSERT tblmembers(recid,memid,memname,mememail,activated)
VALUES('4','1000004','','','0')
INSERT tblmembers(recid,memid,memname,mememail,activated)
VALUES('5','1000005','','','0')

So, the basic concept is that when a membership registration form is
submitted, I want to go and get the next unassigned member id
(activated=0) change the activated flag to 1 and update memname and
mememail fields with parameters passed from the form. I then need to
return the value in that record's memid field back to the confirmation
page.

I can do all of this, but I haven't been able to satisfy myself that
there won't be a problem if I get two simultaneous registration
requests.

In essence, I'm trying to figure a way, given the above sample data,
that if there are two simultaneous registration requests, one of them
is returned the row with the member id of 1000003 and one of them is
returned the row with the member id of 1000004. And, it probably goes
without saying, that if there are 3 simultaneous requests, the third
one would be returned the row with the member id of 1000005, and so
on. In other words, no two registrations should return the same member
id.

Given the examples you provided in the link, I was trying to do do
something similar to:

declare @.rowid numeric

UPDATE tblmembers set @.rowid=selmem.recid, activated = 1 where recid =
(SELECT TOP 1 recid from tblmembers where activated = 0) as selmem

return @.rowid

But, of course, this is invalid syntax, since it seems you can't
provide an alias to a subquery in an UPDATE statement as I have
attempoted to do above.

However, the concept was to perform the select and update in the same
statement, return the recid of the selected / updated row, and then
use that recid value to perform another update query etc to provide
the member name and email details.

I'm sorry if this only confuses matters, but my hope is that it
explains a little better what I'm hoping to achieve...

Thank you, again, for your help!

Much warmth,

Murray|||"M Wells" <planetquirky@.planetthoughtful.org> wrote in message
news:unq420d09pagnsd386892b6snq0vf03n8o@.4ax.com...
> On 4 Feb 2004 23:44:05 -0800, sql@.hayes.ch (Simon Hayes) wrote:
> >M Wells <planetquirky@.planetthoughtful.org> wrote in message
news:<j1o220p3uauokindou45q9l305eq8au783@.4ax.com>...
> >> Hi All,
> >>
> [ here there be snippage ]
> >It's not clear from your description why you need to generate the IDs
> >in advance - a simpler approach might be to use an IDENTITY column,
> >and insert directly into the members table for a new registration. You
> >can then return the system-generated value to the client using
> >scope_identity(). This assumes, of course, that the membership ID is
> >simply a number, with no other meaning:
> >create table dbo.Members (
> >MemberID int identity(1,1) primary key,
> >FirstName varchar(50) not null,
> >LastName varchar(50) not null
> >)
> >go
> >insert into dbo.Members (FirstName, LastName)
> >values ('Murray', 'Wells')
> >select 'Your ID is: ' + cast(scope_identity() as char(2))
> >go
> >If you do need some control over the value of the membership ID, then
> >one of these approaches might be suitable:
>http://groups.google.com/groups?q=s...l=en&lr=&ie=UTF
-8&oe=UTF-8&selm=40044e65%241_2%40news.bluewin.ch&rnum=1
> >If this doesn't help, you may want to post the structure (CREATE
> >TABLE) of your members table, along with some sample data, and explain
> >exactly what you want to return to the client.
>
> Hi Simon,
> Thank you very much for your help with this!
> Unfortunately, the need to use pre-generated member ids is a foregone
> issue; it's not something I have any control over.
> I looked at the two examples in the link you provided. The first makes
> sense to me, but I can't formulate a query that makes it do exactly
> what I want. And I don't yet know enough about locking in SQL Server
> to know if the locking hint (UPDLOCK) does what I hope it will do.
> To give you a little extra detail, my test table definition is:
> if exists (select * from dbo.sysobjects where id =
> object_id(N'[dbo].[tblmembers]') and OBJECTPROPERTY(id,
> N'IsUserTable') = 1)
> drop table [dbo].[tblmembers]
> GO
> CREATE TABLE [dbo].[tblmembers] (
> [recid] [int] IDENTITY (1, 1) NOT NULL ,
> [memid] [numeric](18, 0) NULL ,
> [memname] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS
> NULL ,
> [mememail] [varchar] (255) COLLATE
> SQL_Latin1_General_CP1_CI_AS NULL ,
> [activated] [bit] NULL
> ) ON [PRIMARY]
> GO
> ALTER TABLE [dbo].[tblmembers] WITH NOCHECK ADD
> CONSTRAINT [PK_tblmembers] PRIMARY KEY CLUSTERED
> (
> [recid]
> ) ON [PRIMARY]
> GO
> CREATE UNIQUE INDEX [IX_tblmembers_memid] ON
> [dbo].[tblmembers]([memid]) ON [PRIMARY]
> GO
>
> INSERT tblmembers(recid,memid,memname,mememail,activated)
> VALUES('1','1000001','John Smith','john@.smith.com','1')
> INSERT tblmembers(recid,memid,memname,mememail,activated)
> VALUES('2','1000002','Jen Smith','smith@.jen.com','1')
> INSERT tblmembers(recid,memid,memname,mememail,activated)
> VALUES('3','1000003','','','0')
> INSERT tblmembers(recid,memid,memname,mememail,activated)
> VALUES('4','1000004','','','0')
> INSERT tblmembers(recid,memid,memname,mememail,activated)
> VALUES('5','1000005','','','0')
> So, the basic concept is that when a membership registration form is
> submitted, I want to go and get the next unassigned member id
> (activated=0) change the activated flag to 1 and update memname and
> mememail fields with parameters passed from the form. I then need to
> return the value in that record's memid field back to the confirmation
> page.
> I can do all of this, but I haven't been able to satisfy myself that
> there won't be a problem if I get two simultaneous registration
> requests.
> In essence, I'm trying to figure a way, given the above sample data,
> that if there are two simultaneous registration requests, one of them
> is returned the row with the member id of 1000003 and one of them is
> returned the row with the member id of 1000004. And, it probably goes
> without saying, that if there are 3 simultaneous requests, the third
> one would be returned the row with the member id of 1000005, and so
> on. In other words, no two registrations should return the same member
> id.
> Given the examples you provided in the link, I was trying to do do
> something similar to:
> declare @.rowid numeric
> UPDATE tblmembers set @.rowid=selmem.recid, activated = 1 where recid =
> (SELECT TOP 1 recid from tblmembers where activated = 0) as selmem
> return @.rowid
> But, of course, this is invalid syntax, since it seems you can't
> provide an alias to a subquery in an UPDATE statement as I have
> attempoted to do above.
> However, the concept was to perform the select and update in the same
> statement, return the recid of the selected / updated row, and then
> use that recid value to perform another update query etc to provide
> the member name and email details.
> I'm sorry if this only confuses matters, but my hope is that it
> explains a little better what I'm hoping to achieve...
> Thank you, again, for your help!
> Much warmth,
> Murray

I think this is what you're looking for, assuming that your definition of
the 'next' row is the one with the lowest value for memid within the set of
rows which have an activated value of 0:

declare @.memid int,
@.memname varchar(50),
@.mememail varchar(255)

set @.memname = 'John Doe'
set @.mememail = 'john@.doe.com'

begin tran

select @.memid = min(memid)
from tblmembers with(updlock)
where activated = 0

update tblmembers
set activated = 1, memname = @.memname, mememail = @.mememail
where memid = @.memid

commit

select @.memid

Since you're returning the memid, but updating the other columns, you can't
use the UPDATE syntax I suggested in the link - you'll have to use the
locking hint, which needs to be inside a transaction. Note that I haven't
put any error handling in the code above, but you should definitely put it
in your real code. Here is a helpful resource:

http://www.sommarskog.se/error-handling-II.html

One other point is that having both the recid and memid columns seems to be
redundant - the natural primary key of the table appears to be memid (and
mememail may also be a candidate key), so it's not clear what purpose recid
serves, although I appreciate that you may not have complete control over
the schema, and that you may have simplified your real data here.

Simon|||[ here there be snippage ]

>I think this is what you're looking for, assuming that your definition of
>the 'next' row is the one with the lowest value for memid within the set of
>rows which have an activated value of 0:
>declare @.memid int,
> @.memname varchar(50),
> @.mememail varchar(255)
>set @.memname = 'John Doe'
>set @.mememail = 'john@.doe.com'
>begin tran
>select @.memid = min(memid)
>from tblmembers with(updlock)
>where activated = 0
>update tblmembers
>set activated = 1, memname = @.memname, mememail = @.mememail
>where memid = @.memid
>commit
>select @.memid
>
>Since you're returning the memid, but updating the other columns, you can't
>use the UPDATE syntax I suggested in the link - you'll have to use the
>locking hint, which needs to be inside a transaction. Note that I haven't
>put any error handling in the code above, but you should definitely put it
>in your real code. Here is a helpful resource:
>http://www.sommarskog.se/error-handling-II.html
>One other point is that having both the recid and memid columns seems to be
>redundant - the natural primary key of the table appears to be memid (and
>mememail may also be a candidate key), so it's not clear what purpose recid
>serves, although I appreciate that you may not have complete control over
>the schema, and that you may have simplified your real data here.

Hi Simon,

Thank you, thank you, thank you!

This seems to be doing exactly what I need it to do!

One question, though -- the min() function in the select statement
seems to slow the execution of the stored procedure considerably.

Is there anything wrong with simply using:

select Top 1 @.memid = memid from tblmembers with(updlock)
where activated = 0

My own testing _seems_ to establish this as being somewhat faster...

Again, thank you, thank you, thank you!

Much warmth,

Murray|||M Wells (planetquirky@.planetthoughtful.org) writes:
> This seems to be doing exactly what I need it to do!
> One question, though -- the min() function in the select statement
> seems to slow the execution of the stored procedure considerably.
> Is there anything wrong with simply using:
> select Top 1 @.memid = memid from tblmembers with(updlock)
> where activated = 0
> My own testing _seems_ to establish this as being somewhat faster...

Permit me to bump in here. I was about to suggest something last night
that was akin to what Simon proposed. But then I was struck of a sense
of doubt whether it would work or not. You see, the standard question
is about get the next value to insert. This pre-generated thing changes
the playing rules a bit. So I left your message unanswered and went to
bed.

Problem is that it is now about 24 hourse since I saw your question the
first time, which means that also today the bed is waiting for me. But
I can aleast provide a tip on how to test this. Add this statement to the
batch between the SELECT and the UPDATE:

WAITFOR DELAY '00:00:10'

Then run the batch from two different windows in Query Analyzer, and
see if you get the expected result.

Also, change the design of the table, so that the clustered index is
on memberid (you would do best in dropping recid; it serves no purpose),
and add a non-clustered index on activated. This may be good for
performance.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||On Thu, 5 Feb 2004 23:46:45 +0000 (UTC), Erland Sommarskog
<sommar@.algonet.se> wrote:

>M Wells (planetquirky@.planetthoughtful.org) writes:

[ here there be snippage ]

>Permit me to bump in here. I was about to suggest something last night
>that was akin to what Simon proposed. But then I was struck of a sense
>of doubt whether it would work or not. You see, the standard question
>is about get the next value to insert. This pre-generated thing changes
>the playing rules a bit. So I left your message unanswered and went to
>bed.

(Laugh) Hi Erland -- you're more than welcome to bump in! Thank you
for adding your thoughts...

>Problem is that it is now about 24 hourse since I saw your question the
>first time, which means that also today the bed is waiting for me. But
>I can aleast provide a tip on how to test this. Add this statement to the
>batch between the SELECT and the UPDATE:
> WAITFOR DELAY '00:00:10'
>Then run the batch from two different windows in Query Analyzer, and
>see if you get the expected result.

Thank you for this suggestion -- I was wondering how to test if it
works, and it seems to do just that.

>Also, change the design of the table, so that the clustered index is
>on memberid (you would do best in dropping recid; it serves no purpose),
>and add a non-clustered index on activated. This may be good for
>performance.

The suggestion re the memberid field makes a lot of sense, but the
activated field is currently a BIT type. I was under the impression
you can't put indexes on BIT fields?

I've been wondering if there would be any benefit in changing this to
a TINYINT type so I can put an index on it. Storage isn't an issue,
however speed is.

Thanks, again, for your input -- and hope you got some good sleep.

Much warmth,

Murray|||M Wells (planetquirky@.planetthoughtful.org) writes:
> The suggestion re the memberid field makes a lot of sense, but the
> activated field is currently a BIT type. I was under the impression
> you can't put indexes on BIT fields?

Did you say which version of SQL Server you are using? It's correct that
in SQL7 and earlier, you cannot have bit column in indexes. However, in
SQL2000 this restriction is lifted.

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||On Fri, 6 Feb 2004 09:14:36 +0000 (UTC), Erland Sommarskog
<sommar@.algonet.se> wrote:

>M Wells (planetquirky@.planetthoughtful.org) writes:
>> The suggestion re the memberid field makes a lot of sense, but the
>> activated field is currently a BIT type. I was under the impression
>> you can't put indexes on BIT fields?
>Did you say which version of SQL Server you are using? It's correct that
>in SQL7 and earlier, you cannot have bit column in indexes. However, in
>SQL2000 this restriction is lifted.

Hi Erland,

Hmmm. I'm using SQL2000, but I don't see bit columns when I create
indexes using the Manage Indexes / Keys dialogue...

Do I need to create indexes for bit columns via SQL statements?

Much warmth,

Murray|||On Fri, 06 Feb 2004 14:09:45 GMT, M Wells
<planetquirky@.planetthoughtful.org> wrote:

>On Fri, 6 Feb 2004 09:14:36 +0000 (UTC), Erland Sommarskog
><sommar@.algonet.se> wrote:

[ here there be snippage ]

>Hi Erland,
>Hmmm. I'm using SQL2000, but I don't see bit columns when I create
>indexes using the Manage Indexes / Keys dialogue...
>Do I need to create indexes for bit columns via SQL statements?

Hi Erland,

No need to reply to the above -- I discovered that, yes, I can create
indexes on bit columns via SQL...

However, if I can be forgiven for one last question: given one or more
bit columns in the WHERE clause of a select statement, should I
explicitly CAST the value I'm looking for as a bit?

I came across this tip while surfing for information on bit columns,
but wasn't certain if this remained relevant fro SQL2K...

Many thanks to both you and Simon for all of your help!!

Much warmth,

Murray|||"M Wells" <planetquirky@.planetthoughtful.org> wrote in message
news:3sf720plrd91o572otgvri3pga73nrrej7@.4ax.com...
> On Fri, 06 Feb 2004 14:09:45 GMT, M Wells
> <planetquirky@.planetthoughtful.org> wrote:
> >On Fri, 6 Feb 2004 09:14:36 +0000 (UTC), Erland Sommarskog
> ><sommar@.algonet.se> wrote:
> [ here there be snippage ]
> >Hi Erland,
> >Hmmm. I'm using SQL2000, but I don't see bit columns when I create
> >indexes using the Manage Indexes / Keys dialogue...
> >Do I need to create indexes for bit columns via SQL statements?
> Hi Erland,
> No need to reply to the above -- I discovered that, yes, I can create
> indexes on bit columns via SQL...
> However, if I can be forgiven for one last question: given one or more
> bit columns in the WHERE clause of a select statement, should I
> explicitly CAST the value I'm looking for as a bit?
> I came across this tip while surfing for information on bit columns,
> but wasn't certain if this remained relevant fro SQL2K...
> Many thanks to both you and Simon for all of your help!!
> Much warmth,
> Murray

As far as I'm aware, there shouldn't be any need to explicitly CAST the
value to a bit, but I haven't used bit columns much, so I can't say for
sure.

To answer your previous question:

"Is there anything wrong with simply using:

select Top 1 @.memid = memid from tblmembers with(updlock)
where activated = 0"

The issue here is that TOP without ORDER BY doesn't really mean anything -
you will get one row returned, but in theory you could get any row where
activated = 0. In practice, if you have a clustered index on the table, then
you'll probably get rows back in the order of that index, but there's no
guarantee.

So if your business rule requires you to get the lowest possible memid, then
you would need to do this:

select Top 1 @.memid = memid
from tblmembers with(updlock)
where activated = 0
order by memid asc -- this defines what TOP means

This is effectively the same as my query, of course.

Simon|||M Wells (planetquirky@.planetthoughtful.org) writes:
> However, if I can be forgiven for one last question: given one or more
> bit columns in the WHERE clause of a select statement, should I
> explicitly CAST the value I'm looking for as a bit?

Yes.

This is because of the conversion rules in SQL Server. If you don't use
cast(), SQL Server will convert the bit column to integer. And whenever
a column is not used in its original shape, SQL Server can no longer
seek an index with this column.

It could still opt to scan the index, but it would have to scan all
pages for the index. However, for you repro, I got a table scan when
I did not use cast(). This may be due to the small size of the table.
However, when I used cast(), SQL Server used an Index Seek.

I think that even with a large members table, this method should be
really fast, although there is a cost for updating the index when you
activate the customer.

I also did some concurrency studies, and I feel fairly confident that
the method with UPDLOCK is safe.

Here is a repro, so you can see exactly what I ran:

CREATE TABLE [dbo].[tblmembers] (
[memid] [numeric](18, 0) NOT NULL ,
[memname] [varchar] (50) NULL,
[mememail] [varchar] (255) NULL ,
[activated] [bit] NOT NULL,
CONSTRAINT PK_tblmembers PRIMARY KEY CLUSTERED (memid)
)
GO

CREATE INDEX isactivated ON tblmembers(activated)
GO

INSERT tblmembers(memid,memname,mememail,activated)
VALUES('1000001','John Smith','john@.smith.com','1')
INSERT tblmembers(memid,memname,mememail,activated)
VALUES('1000002','Jen Smith','smith@.jen.com','1')
INSERT tblmembers(memid,memname,mememail,activated)
VALUES('1000003','','','0')
INSERT tblmembers(memid,memname,mememail,activated)
VALUES('1000004','','','0')
INSERT tblmembers(memid,memname,mememail,activated)
VALUES('1000005','','','0')
go
declare @.memid int,
@.memname varchar(50),
@.mememail varchar(255)

set @.memname = 'John Doe'
set @.mememail = 'john@.doe.com'

begin tran

select @.memid = min(memid)
from tblmembers with(updlock)
where activated = convert(bit, 0)

update tblmembers
set activated = 1, memname = @.memname, mememail = @.mememail
where memid = @.memid

commit

select @.memid

--
Erland Sommarskog, SQL Server MVP, sommar@.algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techin.../2000/books.asp|||On Fri, 6 Feb 2004 23:06:17 +0000 (UTC), Erland Sommarskog
<sommar@.algonet.se> wrote:

[ here there be snippage ]

I just wanted to give a heartfelt thanks to both of you (Simon and
Erland) for all of your help with this.

I can't imagine a better testimony for the internet than the fact that
people like you two (and many others) go out of your way to share your
knowledge and expertise with a complete stranger who is struggling to
get something done.

Thank you both, again!

Much warmth,

Murray
http://www.planetthoughtful.org

Monday, February 20, 2012

Position opening : Web Database Programmer (Part-time temp)

I am a small business entrepreneur, and interested in
developing my own web site.
I am currently looking for a Database Programmer, who
has the skill set of MySQL , PHP running on a Linux AS
Platform.

Time is essence for this project. The front-end has
been built properly even though has not been launched
yet, we need the back- end to be done with in 3 weeks.

If you are interested in helping us to build the
back-end

Pls email to me at hhconsultinginc@.yahoo.com with your working experience or Resume.

Let me know if you have any question.

LarryWhere in Jersey?

And to build the front end then build then backened is ah...backwards...

What is the app meant to do?

Did you build an ER logical model?

Any Business flow models?

Data Models?

who is and how big is the User community?

Ports used by ReportViewer web controls

When a ReportViewer control is used to access a report on a remote SQL Server database, on what ports does the communcation occur? Does the control communicate on on the SQL Server ports of 1433 and 1434 or does it communcate as a web service on port 80 (or 443 for HTPPS)?It will depend on the url that you set for the report server. For a standard url it will use 80 (and 443), however you can always pass in a url for a non-standard port.

Ports

What ports would I need to open for a web server in a DMZ to communicate
with an internal SQL server?
Peter,
If it is a standard install you would need to open TCP port 1433 (the
default instance) and/or UDP port 1434 on the same ip if you have any apps
that Sql needs to listen for. If Sql is a named instance the port is
dynamically assigned when the instance is first started unless you set an
alternate port during setup. You can also configure/customize these values
using the Client Network Utility.
Hope this helps.
|||Thanks for the advice!
"Brian Brown" <BrianBrown@.discussions.microsoft.com> wrote in message
news:74EABE7C-8E6B-4467-8728-6BEC92BF678E@.microsoft.com...
> Peter,
> If it is a standard install you would need to open TCP port 1433 (the
> default instance) and/or UDP port 1434 on the same ip if you have any apps
> that Sql needs to listen for. If Sql is a named instance the port is
> dynamically assigned when the instance is first started unless you set an
> alternate port during setup. You can also configure/customize these
values
> using the Client Network Utility.
> Hope this helps.