sql

Insert User Data to Database with INSERT statement

From a user form: I am trying to insert the following data: 1) First Name 2) Last Name 3) Major 4) Graduation Year I am able to connect to the database, and select the database I need--but I am unable to insert the data from the form. I am able to create records, but the data is not being saved to the database. Basically, right now I'm ...

Fight against INNER JOINS - Chapter: unknown column

SELECT p.id FROM produkty p, przyporzadkowania pr, stany_magazynowe, gk_grupy_produkty INNER JOIN sub_subkategorie ssi ON pr.sub_subkategorie_id = ssi.ID Tables and their important fields produkty - id, pozycja przyporzadkowania - id, produkt_id, sub_kategoria_id, sub_subkategoria_id sub_subkategorie - id, subkategorie_id, pozycja sub...

Issue with join and 2 exact column names

Hello all. Never came across this before... SELECT ".TBL_USERS.".username, ".TBL_USERS.".id, <-----------| ".TBL_COMMENTS.".creator, | ".TBL_COMMENTS.".comment, |- same column name ".TBL_COMMENTS.".date, | ".TBL_COMMENTS.".id <---------| As you can see, I am selecting two id colu...

Maximum stored procedure, function, trigger, or view nesting level exceeded in Visual Studio (ado.net) but not in SQL server.

I have a problem with a recursive SQL function. The original problem is that I've got a list of employees, each of them has various trainings. Each of these trainings has some pre requirements. For example to have your Class 1 drivers license you must have your Class 5. If I remove the Class 5 I need to check disable the Class 1. Now as...

Sql Server Displaying Items in specific order

I have a list of items ItemName Manufacturer TopSalesUnit Item1 A 100 Item2 A 80 Item3 A 60 Item4 B 70 Item5 B 50 Item6 B 30 Item7 C 10 Item8 C 05 I would like the re...

Could not open a connection to SQL Server

I have problems connecting to my database server. The database server is not local, I am connected via its IP address. It works fine in my development machine. After publishing the website to my server, it can not connect to my database server. A network-related or instance-specific error occurred while establishing a connection t...

SQL keyword BETWEEN numbers is not catching equal?

I have this simple query: SELECT High, Low FROM prices WHERE Stock = 'XXX' and Date = '2010-02-05' and Low <= 14.88 AND High >= 14.88 Now for 2010-02-05 Low=14.88 and High=15.88 How come the query return empty? It's running on MySQL 5.0.41 Thanks! ...

Inserting a Date into Database

I'm trying to retrieve user data form a form and save the data into a database. I'm trying to retrieve the following data: 1) First Name 2) Last Name 3) Major 4) Year SQL syntax: CREATE TABLE `tblStudents` ( `id` int(11) NOT NULL AUTO_INCREMENT, `first_name` varchar(30) NOT NULL, `last_name` varchar(50) NOT NULL, `major` varc...

Why isn't index used for this query?

I have a table with 300K rows and b-tree index on "operator" field. While I'm runnig this query it isn't using an index. "operator" has the same data-type as dict.vw_dict_operator.id. EXPLAIN SELECT id, name FROM dict.vw_dict_operator self WHERE EXISTS ( SELECT 42 FROM ti.ti_flight_availabilit...

How do I create a dynamic where clause using a List in LINQ to SQL?

var query_loc = (from at in db.amenities_types join a in db.amenities on at.id equals a.amenities_type join u in db.unitInfos on a.unit_id equals u.id join l in db.locations on u.locations_id equals l.id join o in db.organizations on l.organization_id eq...

How do I get just the Nth row of data from sybase?

I have a table with multiple rows for each user. Each user will have the same number of rows but the row ids are all different for each user, so how I do get just the Nth row for a given user? Assuming an order by user_id, row_id clause so you can be guaranteed a consistent order for any given user. This is sybase 12 I'm working with h...

msg102 level 15 error - sql server

I was trying to run a script to create a DB with all the tables and data on a server, which I created using script wizard in SSMS 2008. The destination server is 2005 and since I am unable to just restore a backup, I had to go through this long process which entailed running it through sqlcmd cause it was too large to open in SSMS. But a...

Best practice for organizing SQL queries in code?

I have a bunch of beautiful OOP code but the functions have these monstrously huge SQL queries. In 2010, should we really still be writing our queries in-line or is there an abstraction, like MVC, for SQL queries in PHP? Thank you for your insights. Edit: I probably should have mentioned this here. But as a professional PHP engineer,...

SQL server 2008 multiple "LIKE" problem

I'm using MS SQL 2008 and I'm facing a challenge for a few day's now. My SP parameter can contain one to three words in a string (nvarchar) and I have to return matching LIKE %phrase% records for each word in a string. Example. My parameter is: "stack overflow" Records that must be returnd: miSTACKon noOVERFLOWon STACKit poOWERFLOW...

Implement ROW_Number() to a Specific query

I have the following query that returns a set of rows based on some input parameters : WITH hierarchy AS ( SELECT yt.id FROM [dbo].[TH_Categories] yt WHERE yt.ID = @topicID And CultureID = @cultureID UNION ALL SELECT yt.id FROM [dbo].[TH_Categories] yt JOIN hierarchy h ON h.ID = yt.Pa...

Are there any ORM frameworks for Web SQL (javascript)?

Anyone knows if there's one available now or will be in a near future? ...

Date difference in mysql

Hi, In a mysql table for a date column(login_time), i need to get the logins for last 30 days, last 60 days. Is there any way to do that? Thanks. ...

SQL Server Query to return Trustee Name, and the first occurence of an Event each day within a Date Range

Current query gives me all event_type = 1, for every day after 8/1/2010 I only want the first occurrence per trustee of event_type 1 for each day after 8/1/2010. SELECT trustee, event_time, event_type FROM mytable WHERE event_type = 1 AND event_time > '8/1/2010' Order BY event_time; ...

SQL query: How to count frequency over a many-to-many relation?

I have a table for blogposts and a table for tags, with a many-to-many relation between them. How can I extract the most frequent tag across a subset of blogposts? (e.g. only those from the past year) Is there a way to extract the frequencies of all the tags associated with the blogposts subset? Thanks Edit: my schema: CREATE TABLE ...

One INSERT with UNIONS or multiple INSERTS?

I have a sql function that returns a table. The table is populated via 6 or so reasonably complex statements. Is it better to UNION together these statement so there is only 1 insert or are these better kept separate? Or does it make no difference whatsoever? ...