sql

Problem with a SQL statement

I'm trying to enter values into a database table using a form and a PHP function. The PHP seems to be fine as the SQL statement it creates looks okay, but the database always throws up an error. This is the SQL statement that my code has generated (with arbitrary values): INSERT INTO Iteminfo ('itemName', 'itemSeller', 'itemCategory', '...

What is the purpose of putting an 'N' in front of function parameters in TSQL?

What is the purpose of putting an 'N' in front of function parameters in TSQL? For example, what does the N mean in front of the function parameter in the following code: object_id(N'dbo.MyTable') ...

MySQL query to find customers who have made the most orders

tbl_customer.id is the customer's id tbl_order.customer_id a query that will select all customers with say 4 or more records in tbl_order ...

Correct model for a database with a table for each user.

Kinda stuck here... I have an application with lets say 5000 rows of data per user and was wondering if it was right or wrong to do it this way: On user account creation a new table is created (UserData_[UserID]) or should I just have 1 table for userdata and have everything in there with a column for userid? The reason I am stuck at ...

constructing dynamic In Statements with sql

Suppose we need to check three boolean conditions to perform a select query. Let the three flags be 'A', 'B' and 'C'. If all of the three flags are set to '1' then the query to be generated is SELECT * FROM Food WHERE Name In ('Apple, 'Biscuit', 'Chocolate'); If only the flags 'A' and 'B' are set to '1' with C set to '0'. Then the fol...

Limiting Subscriptions to be emailed using SSRS

Currently, our system will do a "foreach" over all Subscriptions which are returned from the ListSubscriptions method of ReportingService and fire a Timed Subscription event so that they receive the report as an email. In our dev environment, I don't want every subscription of these reports to be sent out when we are testing. Is there ...

how to pull and display range (min-max) data for each page in pagination?

I have a table of data that is searchable and sortable, but likely to produce hundreds or thousands of results for broad searches. Assuming the user searches for "foo" and sorts the foos in descending price order I'd like to show a quick-jump select menu like so: <option value="1">Page 1 ($25,000,000 - $1,625,000)</option> <option value...

SQL select order by decimal precision desc

I'm interested in finding the most precise decimal values in a database field. I'd like to be able to sort results by descending precision. Is this possible? e.g. 10.1781253 12345.12435 89.763 1.1 2 ...

Getting average from 3 columns in SQL Server

I have table with 3 columns(smallint) in SQL Server 2005. Table Ratings ratin1 smallint, ratin2 smallint ratin3 smallint These columns can have values from 0 to 5 How to select average value of these fields, but only compare fields where value is greater then 0. So if column values are 1,3,5 - average had to be 3 if values are 0,3,...

SQL last day in moth select

I have the following table which is basically the summary of daily transactions and is loaded nightly. +++++++++++++++++++++++ + DateCreated + Sale + +++++++++++++++++++++++ + 20100101 + 1000 + + 20100131 + 2000 + + 20100210 + 2000 + + 20100331 + 4000 + +++++++++++++++++++++++ I need to display the sale by month, but ...

Visual Studio 'SQL Server 2008 Server Project' vs. 'Sql Server 2008 Database project' ?

I can't see to find a quick explanation of the differences so I can figure out which to use. One is for a server one is for a Database? Im not sure what that means.. Basically we are doing a new web app and I want to see what these project types can offer me in terms of tracking the DB code/schema etc.. ...

Run MySQL INSERT Query multiple times (insert values into multiple tables)

Hi, basically, I have 3 tables; users and projects, then I have 'users_projects' to allow the one-to-many formation. When a user adds a project, I need the project information stored and then the 'userid' and 'projectid' stored in the usersprojects table. It sounds like its really straight forward but I'm having problems with the syntax...

How do you transfer all your connection configuration from one RapidSQL install to another?

Has anyone encountered this problem? I have installed RapidSQL on a new team member's machine, and now I want to configure his installation with my connection configuration (20+ connections). Does anyone know how to do this? Is there a file RapidSQL uses to transfer this information? Thanks for any feedback. ...

MS-Access: TableAdapter UpdateCommand for table without primary key

What's the syntax for an Update query for a table without a primary key? Disclaimer: Frustratingly, adding a primary key is not an option. My program is a small program in a much larger system with poor data management. My development time does not include rewriting the other software. Note: The database is Microsoft Access. Note: S...

Beginner Question: For extract a large subset of a table from MySQL, how does Indexing, order of tables affect speed of query?

Sorry if this is too simple, but thanks in advance for helping. This is for MySQL but might be relevant for other RDMBSs tblA has 4 columns: colA, colB, colC, mydata, A_id It has about 10^9 records, with 10^3 distinct values for colA, colB, colC. tblB has 3 columns: colA, colB, B_id It has about 10^4 records. I want all the records fr...

How to control order of assignment for new identity column in SQL Server?

I have a table with CreateDate datetime field default(getdate()) that does not have any identity column. I would like to add identity(1,1) field that would reflect same order of existing records as CreateDate field (order by would give same results). How can I do that ? I guess if I create clustered key on CreateDate field and then add...

How to add condition on multiple-join table

Hi, I have those two tables: client: id (int) #PK name (varchar) client_category: id (int) #PK client_id (int) category (int) Let's say I have those datas: client: {(1, "JP"), (2, "Simon")} client_category: {(1, 1, 1), (2, 1, 2), (3, 1, 3), (4,2,2)} tl;dr client #1 has category 1, 2, 3 and client #2 has only category 2 ...

basic sql group by with percentage

I have an issue and NO it is not homework, it's just a programmer who has been away from SQL for a long time having to solve a problem. I have the following table: create table students( studentid int identity(1,1), [name] varchar(200), [group] varchar(10), grade numeric(9,2) ) go The group is something arbitrary...

Multiple column subselect in mysql 5 (5.1.42)

This one seems to be a simple problem, but I can't make it work in a single select or nested select. Retrieve the authors and (if any) advisers of a paper (article) into one row. I order to explain the problem, here are the two data tables (pseudo) papers (id, title, c_year) persons (id, firstname, lastname) plus a link table w/one e...

Is it possible anyhow to raise system exception on catching exception manually?

I am writing a stored procedure where i m using try catch block. Now i have a unique column in a table. When i try to insert duplicate value it throws exception with exception no 2627. I want this to be done like this if (exists(select * from tblABC where col1='value')=true) raiseError(2627)--raise system error that would have thrown...