If I am creating temporary tables, that have 2 columns. id and score. I want to to add them together.
The way I want to add them is if they each contain the same id then I do not want to duplicate the id but instead add the scores together.
if I have 2 temp tables called t1 and t2
and t1 had:
id 3 score 4
id 6 score 7
and t2 had:
...
I have a query like this:
SELECT jobs.*,
(CASE WHEN lead_informations.state IS NOT NULL THEN lead_informations.state ELSE 'NEW' END) as lead_state
FROM "jobs"
LEFT JOIN lead_informations
ON lead_informations.job_id = jobs.id
AND lead_informations.mechanic_id = 3
WHERE (lead_state = 'NEW')
Which gives the following error:
PGEr...
Hi Guys,
Need help with the pivot clause in sql server 2008.
I have a table with this info:
Weekno DayOfWeek FromTime ToTime
1 2 10:00 14:00
1 3 10:00 14:00
2 3 08:00 13:00
2 4 09:00 13:00
2 5 14:00 ...
Hi,
why i get error:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS(SELECT id FROM mytable WHERE id = '1')' at line 1
query:
IF EXISTS(SELECT id FROM mytable WHERE id = '1')
Thanks
...
Greetings,
How to create duplicate table (structure only) with new name in the same database in SQL Server 2008?
I have table with 45 fields so I want to create new with same structure but new name.
I do not want to copy the data!!
Thank you,
...
Hello all,
There are two columns. One of them contains HTML and another contains plain text. How can I compare them as 2 plain texts? Converting HTML -> plain text should be done the same way as a browser does when copying selected HTML into clipboard and pasting it into notepad.
Regards,
...
When using FOR XML PATH and WITH XMLNAMESPACES to declare a default namespace, I will get the namespace decleration duplicated in any top level nodes for nested queries that use FOR XML, I've stumbled across a few solutions on-line, but I'm not totally convinced...
Here's an Complete Example
/*
drop table t1
drop table t2
*/
create ta...
Hi
Does anyone know how can I replace the "comment_author_url" field from all comments by running a SQL query?
for example if this field is http://google.com to replace it with "" (empty string)
...
I never thought I'd ever say this but I'd like to have something like the report generator in Microsoft Access. Very simple, just list data from a SQL query.
I don't really care what language is used as long as I can get it done fast.
C#,C++,Python,Javascript...
I want to know the quickest (development sense) way to display data from ...
Assume Table A has two children tables, B and C with cascade delete between A-B, and cascade delete between A-C.
When a row is deleted in A, the matching rows from B and C are deleted.
How does SQL Server determine the order of the Cascades to fire? What I need is to fire the A-C cascade delete before the A-B cascade delete fires.
I k...
I'm writing a stored procedure in SQL Server that joins about 10 tables. When I exclude the join of this particular table from the query, logical reads looks reasonable. When I include it in though, logical reads of some of the tables rise to 9000. This table has primary key clustered, and I'm joining it just like the other tables in the...
I have a table that I need to normalize with many fields In SQL-Server 2000.
It contains 2 fields which I'm using to come up with distinct combination as defined by the specs.
ID and Rate: there are multiple rows of same IDs and Rates
I first created a temp table by grouping the IDs and Rates combination.
SELECT ID, Count(*) AS IDCou...
I've been banging my head against a wall for the past hour trying to figure this out, sql is giving me the following error
Msg 8169, Level 16, State 2, Procedure GetAppointmentsByProfessionalName, Line 6
Conversion failed when converting from a character string to uniqueidentifier.
when this stored procedure is executed
-- ======...
I have a VS 2010 solution I've been doing schema comparisons with a DB 2008 project.. It's been working against my local SQL as well as a dev/staging database. i checked out the project on another computer, and now when trying to compare down to the local express db I get the following error. "You cannot write updates to the target whe...
I've got this stored procedure, and when I add the join I get no results. Is this because the column used for the join condition, ForClientID, is null? Would that affect the results of the table? If i select the table with Appointment.ForClientID instead of Client.Name, the rest of the table loads with the ForClientID column being null. ...
I'm currently writing a WCF web service that uses LINQ to SQL to fetch work with a SQL database.
I have a Users table that had an integer that stores how many requests to the service the user has done. During testing I'm getting some concurrency probs updating the integer if its being done at the same time.
What would be the best way t...
Hey, I am new to Oracle SQL and I am trying to make a trigger which has an insert dependent on columns received from a select query.
I have a basic fantasy baseball app and I am trying to update a table which correlates the player to the team he played on for a single day. The basic idea i want to do is to update the date for each team...
Hi,
As per requirement i need to get the information whether an user is present in given database or not. Whether there is any stored procedure which i can use to get this information of user. I just want to check whether user is present in given database, and proceed further with my usage.
I am using MSSQL Server 2005.
Also i need an...
I have two models, Project and Category, which have a many-to-many relationship between them. The Project model is very simple:
class Project < ActiveRecord::Base
has_and_belongs_to_many :categories
scope :in_categories, lambda { |categories|
joins(:categories).
where("categories.id in (?)", categories.collect(&:to_i))
}
...
I have created a table called STUDENT which consists of Unique ID as the PRIMARY KEY along with other related attributes like Name, Addr, Gender etc....
Since I don't want to increase the table size of the STUDENT, I created a weak entity called ACADEMIC RECORDS which stores the previous Academic Records of the student.But in this table...