473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

examples

I see a lot of example, but where do these example procedures go. Like
declare (whatever)?
below is an example i read. Where do you put this to make it execute, is it
the view screen or the stored procedure screen?
I'm using MSDE now to learn, and I can't get nothing working except simple
select query statements.

In the northwind example (northwindcs), how would I do a parameter query
like this:
Have a dialog box ask user to enter customerid to bring up. (in a query now
not a form)
Also, how would you check if a certain customerid exist? Example, CHOPS is
one customerid. If I wanted to use a query to check if it exist, and return
no records, but just do an action (like add a record) if it didn't exist,
how?
CPU SQL
(ms)
-- Convert to varchar (implicitly) and compare right two digits
-- (original version -- no I didn't write it)
4546 select sum(case right(srp,2)
when '99' then 1 when '49' then 1 else 0 end)
from sf

-- Use LIKE for a single comparison instead of two, much faster
-- Note that the big speedup indicates that
-- CASE expr WHEN y then a WHEN z then b .
-- recalculates expr for each WHEN clause
2023 select sum(case when srp like '%[49]9' then 1 else 0 end)
from sf

I tried some variations of this, and indeed it seems that there is a cost
when the expression appears with several WITH clauses. I tried a variation
of this, where I supplemented the test table with a char(2) column, so I
could factor out that the WITH clauses themselves were not the culprits.

CREATE TABLE realthing (realta real NOT NULL,
lasttwo char(2) NOT NULL)
go
INSERT realthing (realta, lasttwo)
SELECT r, right(r, 2)
FROM (SELECT r = convert(real, checksum(newid()))
FROM Northwind..Orders a
CROSS JOIN Northwind..Orders b) AS f
go
DBCC DROPCLEANBUFFERS
go
DECLARE @start datetime
SELECT @start = getdate()
SELECT SUM(CASE right(realta, 2)
WHEN '99' THEN 1
WHEN '49' THEN 1
WHEN '39' THEN 1
ELSE 0 END)
FROM realthing
SELECT datediff(ms, @start, getdate()) -- 20766 ms.
go
DBCC DROPCLEANBUFFERS
go
DECLARE @start datetime
SELECT @start = getdate()
SELECT SUM(CASE WHEN right(realta, 2) LIKE '[349]9' THEN 1 ELSE 0 END)
FROM realthing
SELECT datediff(ms, @start, getdate()) -- 8406 ms.
go
DBCC DROPCLEANBUFFERS
go
DECLARE @start datetime
SELECT @start = getdate()
SELECT SUM(CASE lasttwo
WHEN '99' THEN 1
WHEN '49' THEN 1
WHEN '39' THEN 1
ELSE 0 END)
FROM realthing
SELECT datediff(ms, @start, getdate()) -- 920 ms.
go
DBCC DROPCLEANBUFFERS
go
DECLARE @start datetime
SELECT @start = getdate()
SELECT SUM(CASE WHEN lasttwo LIKE '[349]9' THEN 1 ELSE 0 END)
FROM realthing
SELECT datediff(ms, @start, getdate()) -- 1466 ms.
Thus, when using the char(2) column LIKE is slower despite that there
is only one WHEN condition. So indeed it seems that right(realta, 2)
is computed thrice in the first test.

Another funny thing is the actual results from the queries - they are
different. When I ran:

select count(*) from realthing where lasttwo <> right(realta, 2)

The result was about half of the size of realthing! I can't see that
this difference affects the results though.

Now, your article had a lot more tests, but I have to confess that
you lost me quite early, because you never discussed what is the
actual problem. Since you are working with floating-poiont numbers
there is a great risk that different methods not only has different
execution times, but also gives different results.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #1
2 2512
Since you replied to what was originally my post, I'll respond.

First, MSDE is just a database engine. It may be packaged with other
programming tools (eg. Visual Studio .NET), but is not itself a programming
tool. It is programmable in the sense that you can create stored procedures
and SQL batches, but these have to be entered from some sort of client tool.

re: where do these procedures go...

I'm not very famiar with MSDE. I'm assuming it works just like the full SQL
Server, but is lacking some client tools. I enter all my queries into Query
Analyzer. If you don't have that included with MSDE, perhaps it's worth
spending about $50 for MS SQL Server Developer Edition to get it. But if you
can enter SELECT statements, I think you should be able to enter any
Transact/SQL batch, as long as your database user has the proper access
permissions. It's been a while since I tried it, but I think even Access can
be used to create tables and procedures, using SQL Passthru queries.

My examples were lacking DDL (data definition language, eg CREATE TABLE),
because I didn't think it important that anyone else try running these
queries. Erland provided DDL in his reply.

Everything up to but not including a GO is a batch of SQL statements that
you should be able to enter anywhere a SQL query can be executed, I think,
though you should be using some sort of SQL do ($dbh->do() in Perl DBI) or
SQLExecute() I think (ODBC in C) or cmd.Execute I think (ADO in Visual
BASIC?) or a passthru query that is set to return no results in Access.
Check the documentation for whatever language you are using, because clearly
the use of MSDE (a developer tool) requires the use of some sort of
programming tool to do what you are talking about.

I dont think you should ask how to bring a dialog box up here; that isn't a
SQL question...

re: customerid exists...

If you can execute a SELECT query, you can do this:

SELECT 1 FROM Northwind..Customers
WHERE CustomerID = 'CHOPS'

...using dynamic SQL. But parameterized SQL is more secure, faster, etc.

In Perl using DBI and DBD::ODBC (see www.activestate.com for Perl for
Windows)...

perldoc DBI

# DBItest.pl
my $user = 'SA';
my $auth = 'SAPassword'; #bad practice?
my $dbh = DBI->connect("dbi:ODBC:Northwnd", $user, $auth) || die;
#$dbh->do("USE Northwind");
my $sql = q(SELECT 1 FROM Northwind..Customers
WHERE CustomerID = ?);
# replace with a dialog if you like:
print "Enter customer ID:";
my $custid=<>; #'CHOPS';
chomp $custid;
my $sth = $dbh->prepare($sql) || die;
$sth->execute();
my ($custexists) = $sth->fetchrow_array();
if ($custexists) {
print "Customer $custid exists\n";
} else {
print "Customer $custid does not exist\n";
#display a dialog, retrieve values, etc
#$dbh->do("INSERT northwnd..Customers (...) VALUES (...)");
}

You may prefer to use Visual Basic rather than Perl to build Windows GUI
apps, although it certainly should be possible in Perl as well. If I were
building a GUI app in Perl I might try TCL/Tk:
http://search.cpan.org/~vkon/TclTk-0.75/Tk.pm
..... but again all this is off topic for a SQL newsgroup.

Decide which programming tool you want to use, make sure you have that tool,
check the documentation for the product, then ask your question in a topical
group if you still have problems.

And try a tutorial for the sort of thing you are talking about. Many MS
tools include tutorials for using the Northwind database.

-aaron
"JIMMIE WHITAKER" <kp*****@worldnet.att.net> wrote in message
news:xF*********************@bgtnsc04-news.ops.worldnet.att.net...
I see a lot of example, but where do these example procedures go. Like
declare (whatever)?
below is an example i read. Where do you put this to make it execute, is it
the view screen or the stored procedure screen?
I'm using MSDE now to learn, and I can't get nothing working except simple
select query statements.

In the northwind example (northwindcs), how would I do a parameter query
like this:
Have a dialog box ask user to enter customerid to bring up. (in a query now
not a form)
Also, how would you check if a certain customerid exist? Example, CHOPS is
one customerid. If I wanted to use a query to check if it exist, and return
no records, but just do an action (like add a record) if it didn't exist,
how?
Jul 20 '05 #2
JIMMIE WHITAKER (kp*****@worldnet.att.net) writes:
I see a lot of example, but where do these example procedures go. Like
declare (whatever)? below is an example i read. Where do you put this
to make it execute, is it the view screen or the stored procedure
screen?

I'm using MSDE now to learn, and I can't get nothing working except simple
select query statements.


If you are using MSDE only, there's no GUI tools with it. But you can
use the OSQL comand-line tool to run scripts.

However, judging from your talk of view and stored procedure screens,
it sounds like you have Enterprise Manager available. In such case you
also have Query Analyzer available, from which you can run all sorts of
queries.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Thomas Guettler | last post by:
Hi! I read "How Python is developed" (comp.lang.python.announce), and think that there could be more examples in the docs. One think I really like to see: An example with mycmp(a, b)... in...
1
by: Ron Kneusel | last post by:
I have installed VTK 4.2.6 and Python 2.3.4. Both are working and I can run the VTK Python examples except for those in the GUI directory. These always fail with messages similar to this: ...
14
by: Jim Hubbard | last post by:
I am looking for documentation and code examples on DDML (Display Driver Management Level). It is mentioned in the 2000, XP and 2003 DDKs - but just barely. It has to do with mirroring a...
2
by: Rory Plaire | last post by:
Hi, I've been working with the J# browser control. I understand that v1.1b is scriptable, but can't find any examples on how to do this. Can someone point me in the right direction? thanks,...
1
by: sam++ | last post by:
Hi, I cd into examples/DLL/ and type "make", it failed to compile the example. The error is: # make make - -f DLL_Today.bor all make: don't know how to make all. Stop *** Error code 2 ...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
102
by: Xah Lee | last post by:
i had the pleasure to read the PHP's manual today. http://www.php.net/manual/en/ although Pretty Home Page is another criminal hack of the unix lineage, but if we are here to judge the quality...
4
by: Michael | last post by:
Hi! (OK, slightly silly subject line :) I'm extremely pleased to say - Kamaelia 0.4.0 has been released! What's New & Changed? =====================
1
by: AppleBag | last post by:
Hello I have found examples of using an .mdb file in VS2K3, but apparently the components in the toolbox are different than the ones shown in the 2K3 examples. I have google'd and searched high...
10
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
controlsPlease could some of you here post some of your live examples of AJAX (esp drag panels, collapsable panels, and popup menu.) (It's one thing to talk about how great something is, but it's...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.