|
What SQL implementation are you using?
- Mike
|
|
|
|
|
It will be crossdatabase : Access, MySQL, SQL Server and Oracle (and maybe some others)....
|
|
|
|
|
As far as I know, every SQL implementation has a different way of making autoincrement columns, e.g., MySQL uses the AUTO_INCREMENT modifer, Oracle uses sequence objects, PostgreSQL uses the SERIAL type, SQL Server uses IDENTITY , etc.
- Mike
|
|
|
|
|
These may be a stupid questions, but I have not been able to figure it out except for having a SPs that are slightly different.
Is it possible in a MS-SQL Server T-SQL Stored Procedure to do something like this pseudo code:
SELECT SUM(Amount) FROM Sales
if @StoreID > 0
then WHERE StoreID = @StoreID
else WHERE StoreID > 0
And also something like this, where @StoreID is a comma delimited list of StoreIDs
SELECT SUM(Amount) FROM Sales
if CAST(@StoreID as integer) > 0
then WHERE StoreID = @StoreID
else WHERE StoreID IN (@StoreID)
Note: My SELECT statements are much (much) more complicated than this. These where minimized for clarity.
Maybe I guess the real question is "even if I can do this, should I"? I am trying to minimize the business logic and the number of different SPs I have.
Thanks in advance,
Konstantine
|
|
|
|
|
The first can be done in a rather roundabout way:
SELECT SUM(Amount)
FROM Sales
WHERE
StoreID > 0 AND
StoreID =
CASE
WHEN @StoreID > 0 THEN @StoreID
ELSE StoreID
END This basically works by comparing the StoreID in the table against itself when the variable @StoreID is not greater than 0 (always TRUE, unless you've got any NULL s in your data), as an extra filter clause. It's sometimes possible to exploit these conditions, but you should check the impact on the execution plan in Query Analyzer (it might cause an index to be rejected, leading SQL Server to read every row, killing your performance ).
For the second one, I refer you to http://www.algonet.se/~sommar/arrays-in-sql.html[^] (link found from http://sqljunkies.com/weblog/[^]).
|
|
|
|
|
Mike,
Thanks for your reply.
That is a nice trick. I will give it a try and see how good/bad the performance works out.
Thanks for the links too. I search for a long time and never found anything nearly that useful.
Konstantine
|
|
|
|
|
I am wondering if this is possible with one query?
I want to sum some values based off different customer id values,
for instance:
select sum(value1) as value1_total where customer = '1111'
but also sum(value1) where it equals a customer of '9999'
Thanks,
Chris
|
|
|
|
|
CREATE PROC up_MyTotal
@id INT
AS
select sum(value1) as value1_total where customer = @id
The call teh stored proc twice
|
|
|
|
|
SELECT customer, sum(value1)<br />
FROM my_table<br />
GROUP BY customer
or
SELECT customer, sum(value1)<br />
FROM my_table<br />
WHERE customer IN ('1111', '9999')<br />
GROUP BY customer
|
|
|
|
|
I use a DataView to sort and filter information. How do I get specfic cell out of the DataView? For example I use the DataRowView to display the entire Row. The row appears like this 1 5 10 7 9. Each number represents a different column. I need to get each number indivdually and pass it to a local variable I have created.
myId = 1.
myOtherId = 5.
Any ideas.
thanks
|
|
|
|
|
I want to select some information from one server and join it to another servers information in a query. Is this Possible?
QMuffs
|
|
|
|
|
|
Worked great. Thank you for your time.
QMuffs
|
|
|
|
|
I need help constructing a query for my database application. Please use notepad to view the text file below for the problem's description. Thanks.
http://www.nghiep.com/sqlhelp.txt[^]
|
|
|
|
|
Just a small modification (in bold) to your second query:
<br />
Select e.Event_ID, e.Event_Date, p.Prod_Name from EVENT e, PRODUCT p, EVENTS_PRODUCTS eps<br />
where e.Event_ID = eps.Event_ID and eps.Prod_ID = p.Prod_ID<br />
order by e.Event_ID p.Prod_Name DESC, e.Event_Date DESC<br />
Then the grouping of data can be done in the code that renders the HTML. (Iterate through the results, and create a "group-seperator" only when Event_ID changes...)
|
|
|
|
|
Thanks for trying help...but I think your example would only sort the Prod_Names WITHIN each Event_ID group. But still, at the highest level, the table is sorted by Event_ID, not Prod_Name. I do not want that. I need the table to be sort by Product names.
|
|
|
|
|
Ah... So I need to actually READ your text...
Sorry, my fault...
|
|
|
|
|
i have a perl script file and i have to convert it into the sqlserver2000.;)
puneet
|
|
|
|
|
Hi, please forgive my absolute stupidity. I have been using Access databases for ages, and started using SQL recently.
What is the best way to join tables. I have one table for user details, one of the fields is a bit. Depending on true or false, this will then use one of two other tables. How do you link these? Would I create a uniqueId in the users table, and then use something like a nvarchar to set up a relationship. Bearing in mind, these additional two tables, could hold multiple records of the same user. However, a user cannot appear in both these additional tables.
If I did it the way mentioned above, should i also have an additional uniqueId specific to a record?
|
|
|
|
|
Here's an example:
create table parent(id int primary key, somecolumnnameA varchar(200))<br />
create table child1(id int primary key, parentid int foreign key references parent(id), somecolumnnameB varchar(200))
Generally, you need to have the same datatypes in both the parent and the child tables if you're going to create relationships between them. The parent will need a primary key, and the child will need a foreign key that references the parent's primary key.
|
|
|
|
|
I have a custom filter with a checked listbox and i need to fill it with all the unique values from a specified column in System.Data.DataTable. What is the most efficent way to do this?
TIA,
Peter
|
|
|
|
|
|
I've tried the "select TABLE_NAME from INFORMATION_SCHEMA.TABLES" and tried the sysobjects route too, but the DSN I am using (ODBC) reports that no such table exists within the given database. The DB itself is a MySQL database. I don't want to use any non-standard queries because the code must work across multiple datasources.
Then I went the catalog route and tried:
SQLTables(hstmt3, NULL, 0, NULL, 0, "Orders", SQL_NTS, NULL, 0);
and I get a compile error about param 6 ("Orders") being of the incorrect type - even though I copied and pasted it directly from MSDN.
What should I do to get a listing of the tables in a given ODBC DSN?
|
|
|
|
|
Hey,
Are there any predefined functions in .NET to encode user input for SQL statement compatablity (ie. change "'" to "\'", etc)?
So: "Sam's cat died." would become "Sam\'s cat died."
Thanks,
Adam
-- Adam
"If you can't beat your computer in chess, try kickboxing"
|
|
|
|
|
You should avoid encoding user input into your SQL queries. This is a major security hole:
SELECT MyColumn FROM MyTable WHERE MyOtherColumn={1}
can become
SELECT MyColumn FROM MyTable WHERE MyOtherColumn=0; DELETE FROM MyTable
A better solution is to use stored procedures and pass user input as their parameters.
Alexandre Kojevnikov
MCAD charter member
Leuven, Belgium
|
|
|
|