sql

'questions' and 'answers' with multiple answers

This question is related to this post: http://stackoverflow.com/questions/1764469/sql-design-for-survey-with-answers-of-different-data-types I have a survey app where most questions have a set of answers that are 1-5. Now we have to do questions that could have a variety of different answer types -- numeric, date, string, etc. Thanks to...

SQL merge table and group by

I'm not very good in SQL stuff, so I hope someone can explain this issue to me (and help me solve it) I have a table; ++++++++++++++++++++ | ID | Minutes | ++++++++++++++++++++ | 1012 | 15 | | 1012 | 25 | | 1015 | 45 | | 1016 | 10 | | 1016 | 50 | ++++++++++++++++++++ And I want to achieve, that ...

Which ORM Supports Multiple row Updates and Deletes

I have a query that deletes all rows that have been marked for deletion. There is a column in a table that is named IsDeleted. It is a boolean data type if it is true the row is suppose to be deleted along with all related rows in different tables. If an article row is marked for deletion then the article comments, votes are also supos...

Cannot filter results set in SQL Server query

For some reason I cannot get my results set to restrict products that only have the price status of "normal'. When I use a where clause like where pricestatus like 'normal' the results set also filters other records. Any ideas here? SELECT od.order_id, ISNULL(p.pricestatus,'normal') as pricestatus, ISNULL(od.partnumber,'un...

Sql wildcard: performance overhead?

I've Googled this question and can't seem to find a consistent opinion, or many opinions that are based on solid data. I simply would like to know if using the wildcard in a SQL SELECT statement incurs additional overhead than calling each item out individually. I have compared the execution plans of both in several different test querie...

In SAAS architecture, how do I handle db schema and MVC user logins for multi-tenants

Our requirement is something like this. We are building a multi-tenant website in ASP.NET MVC, and each customer should be able to create their own users as per predefined user roles. We are thinking about to create a schema for few tables which would be common for customers. So customer can login to system according to their schema lo...

mysql dynamic var

Hello All A little confused how to create a query and set a dynamic var in the query for output. Lets say I have a basic table with the following id | name | type | location Now I want to do a query and select all data pretty simple stuff SELECT * FROM TABLE Which will give me ie. 1 | batman | scifi | row a 2 | matrix | scifi | ...

Oracle bug? SELECT returns no dupes, INSERT from SELECT has duplicate rows

I'm getting some strange behaviour from an Oracle instance I'm working on. This is 11gR1 on Itanium, no RAC, nothing fancy. Ultimately I'm moving data from one Oracle instance to another in a data warehouse scenario. I have a semi-complex view running over a DB link; 4 inner joins over large-ish tables and 5 left joins over mid-size tab...

Database design, which table has the foreign key

I have an Table USER (USER_ID, PASSWORD, NAME, ...) and an Table ACCESS_ROLES for the Users, every user can have one ACCESS_ROLE (ONE-TO-ONE). Wich table has the Foreign Key? I would put the USER_ID into ACCESS_ROLES table. Is there any best practice approach? ...

Weird mysql error

Hello I have a mysql database with in it an addresses table. This is the way it's created: CREATE TABLE IF NOT EXISTS `addresses` ( `adr_id` int(11) NOT NULL AUTO_INCREMENT, `per_id` int(11) NOT NULL, `adr_street` varchar(50) NOT NULL, `adr_houseno` int(11) DEFAULT NULL, `adr_housenoadd` varchar(10) DEFAULT NULL, `adr_postc...

DWH style query in Django to generate summary report at specified levels of detail

I have a catalog of items like so: class Items(models.Model): name=models.CharField() type=models.ForeignKey(ItemType) quantity=models.IntegerField() price=models.DecimalField() # Simplified [... other fields] and it has some attributes governed by: class ItemAttributes(models.Model): name=models.CharField() ...

C# SQL Bulk Export

I want to bulk export from a select table, all columns that match a listbox and from only rows that match listings in a text file. Any help? I'm sure someone has done this. ...

Boundless Stored Proceedure Input

I'm passing a comma delimited list of ids to a stored procedure as a varchar(MAX). The problem is varchar caps at 8000 characters and the list could potentially be larger. Is there a sql datatype where size doesn't matter? No pun intended. ...

varchar to number conversion for sorting in MySQL

I have a query ordered by column: select * from mytable order by column asc — sort table column type is varchar, so the output is: 1 10 100 11 12 13 How should I sort if I want them to sort by numeric value so the output is: 1 10 11 12 13 100 Thanks. ...

Customised Ordering in SQL

Hi, I have a SQL query like SELECT column1,column2 FROM table1 WHERE column1 IN('q1','q2','q3') The results are shown in the order: q1 q2 q3 If I change the query to SELECT column1,column2 FROM table1 WHERE column1 IN('q3','q1','q2') Still the order remains same. How to achieve this ordering in the sql statement? Help!! ...

Single Instance Stored Procedure call

Is there any way that I can make sure that a stored procedure completely finishes before another instance of it is started? I have to do 3 things in the procedure and if two instances are running at the same time it will mess up a boundary case. Example: Count rows, if < X insert a row, return calculated Y if multiple instances of ...

How to produce HTML new line by putting metadata in Oracle table.

We have a CRM solution where all metadata stored in Oracle table (don't ask me why). I am issuing an update statement but when get the data from database I see on front end '\n' as part of the text and not new line (like HTML's <br/>). I was trying to put directly in description but it shows as br/ on front end. What escape charact...

mysql select where column not empty

Hi, Trying to figure out if this is possible select columns only where something exists? Example, I have the following query select phone, phone2 from jewishyellow.users where phone like '813%' and phone2 Basically, I'm trying to select only the rows where phone starts with 813 and phone2 has something in it? ...

Debugging SQL Server 2008

I have Visual Studio .Net project which uses ADO connection to call stored procedure of SQL Server database. It is possible to set a breakpoing at stored procedure and debug it. I have local SQL Server and SQL Enterprise Edition installed. ...

How do I get random rows using nhibernate?

How do I select 5 random records using nhibernate. My sql looks like this: SELECT TOP 5 u.UserId, u.UserName, p.ImageFileName FROM users as u, profiles as p WHERE u.UserId = p.UserId ORDER BY NEWID() I tried doing this but it doesn't work IList<User> users = session .CreateCriteria(typeof(User)) ...