I have the following code in my Excel workbook that I copied from this page. Code: Sub Button1_Click() Dim con As ADODB.Connection Dim cmd As ADODB.Command Dim rs As ADODB.Recordset Dim WSP1 As Worksheet Set con = New ADODB.Connection Set cmd = New A
For a table, CARS, with two columns, MAKE and MODEL, I would like to enforce that that for some particular MAKE values, their MODEL values must be unique (assuming this is an Oracle database). For example, I want to enforce duplicates for Ford, but n
Here is my code i need to get the count of male and female separately public function getmaletofemaleCountById() { $select = $this->select(); $select->from($this->_name, array('count(*) AS candidateSum','count(candidate_gender='.MALE.') AS male',
ok, please keep in mind that I am fairly new to SQL Server, though I have built and worked with Access databases, but I always interacted with them using DAO where creating a loop was easy-peazy. Here is what I am trying to do, without success so far
I have a table as ID TOTAL SUM(TOTAL) 1 62 62 1 53 53 2 62 62 2 47 47 I thought the SUM(TOTAL) should look like ID TOTAL SUM(TOTAL) 1 62 115 1 53 115 2 62 109 2 47 109 This is the query I used select ID, TOTAL, SUM(TOTAL) from tablename GROUP BY TOTA
I'm attempting to write a conditional query that inserts new rows into a table from data from another table, but if the PK already exists for that row, to update it instead. I came across ON DUPLICATE KEY UPDATE, but can only find examples that work
I have a MySQL (actually MariaDB) query which is running much slower and falling back on filesort when I try sorting by a DATETIME field (sighted) instead of the primary key. I have an index on sighted, but for some reason it does not seem to be usin
I am new to sql and i have an employee table. I want to create a trigger so that no one can insert a new employee record with salary less than 200. I tried this code but it doesn't accept any record anymore and i see this error "The transaction ended
I have a list of names. john, sam, peter, jack I want to query the same sql with each of above as the filter. Each query will give me a unique employee id, which I want to use to delete some other records. select emp_id from employee where emp_name l
Hi i have a table with following values Country Count China 2 India 3 Pakistan 3 i want these in JSON as "China" : 2,"India" : 3,"Pakistan" : 3 I don't want the header Count and Country. I Have tried using ajax and HTTP Handl
I am attempting to use a sub query to query our order database and return 3 columns for example: Date Orders Replacements 09-MAY-14 100 5 ... ... ... Each order that is created can be given a reason, which basically means that it is a replacement pro
I have tables: Category: Id, Name... News: Id, Title News_Category_Mapping: Id, NewsId, CategoryId Where newsid, categoryid are foreign keys to these 2 tables. News_category_mapping: Id NewsID CategoryId 1 1 1 2 2 1 3 3 1 4 4 3 5 5 5 6 6 3 so i may w
Below is the sql connection code for my php script as it attempts to connect to my Google SQL Cloud Database <?php $con=mysqli_connect(":/cloudsql/projectID:google-cloud-instance","root","root","DATABASE"); // Ch
I'm having a sql table with date column named CREATED_TS which holds the dates in different format eg. as shown below Feb 20 2012 12:00AM 11/29/12 8:20:53 PM Feb 20 2012 12:00AM 11/29/12 8:20:53 PM Feb 20 2012 12:00AM 11/29/12 8:20:53 PM Nov 16 2011
Right I have the following data which i need to insert into a table called locals but I only want to insert it if the street field is not already present in the locals table. The data and fields are as follows: Street PC Locality --------------------
Say I have a table of people... person: ----------- id | person ---+------- 1 | Jim 2 | Bob 3 | Frank ...and I have a table of items... item: ---------------- id | item | type ---+------+----- 1 | 21 | 2 2 | 10 | 5 3 | 11 | 1 4 | 9 | 1 ...and I also
i want to get data from my database where one field is max, at this moment i do this in 2 queries. the thing is i dont want to overload the server so i am looking for a way to make it in 1 query. any suggestions? as you can see i am looking for entry
SELECT orderid FROM (SELECT orderid, rownum r FROM (SELECT orderid FROM myorders WHERE ordertype = 'E' AND orderstatus = 'A') a WHERE rownum < 86) WHERE r > 84 What is the best way to rewrite the ABOVE sql statement in more clear way... I have tried
I was getting confused on how to build the SQL query when it come to joining two tables so that I could bind them later to a gridview. Basically I have two tables, tablename: family __________________________ |Status |lastName|firstName| |-------|---
How to add a column to a SQL Server table with a default value that is equal to value of an existing column? I tried this T-SQL statement: ALTER TABLE tablename ADD newcolumn type NOT NULL DEFAULT (oldcolumn) but it's giving an error: The name "oldco
I have a table with data like the following id name created parent ------------------------------------------------ 1 Alpha 11385209583 0 2 Bravo 11385209619 0 3 Bravo-A 11385209701 2 4 Bravo-B 11385209777 2 such that Bravo-A and Bravo-B are children
I'd like to show how many times a name appears in a field in an Access 2003 table. here's the table structure and content: I used this example here: Tabel: 1 - Name1 1 - Name2 2 - Name1 2 - Name3 3 - Name1 3 - Name2 Result Name1 - 3 Name2 - 2 Name3 -
Write a query to display distinct pair of patients who are treated by the same doctor. The following tables are present: doctor: d_id d_name patient: p_id p_name treatment: d_id p_id disease medicine The query: Select p1.p_name, p2.p_name from patien
I currently have two tables, one is products and the other is options (colour, size, etc). If no options are specified for the product, it puts the stock against the product table Otherwise it will put the stock against the option table Tables look a
I have two basic queries which I need to sum the totals of: Select hours, sum(hours) FROM table WHERE name='xxx' and Description='Worked' Select hours2, sum(hours2) FROM table WHERE name='xxx' and Description2='Worked' I've tried UNION and it will ge
What would be the best way to model 1 table with multiple 1 to many relatiionships. With the above schema if Report contains 1 row, Grant 2 rows and Donation 12. When I join the three together I end up with a Cartesian product and result set of 24. R
Query 1: select PremiumYTDCurrent=Sum((AASI.Inv_Premium)*R.[Percent]), R.STAFF, L.Description, L.LINE_OF_BUSINESS from AAS_Invoice AASI,Invoice I,Revenue_Tracking R, Policy P, Line_Of_Business L where I.Invoice_No=convert(Char,Convert(int,AASI.Inv_En
Is it possible to use select * with distinct or write easily something that has the same impact? I need to select all columns from a table with distinct value, but listing all the columns in select clause would be nerve-breaking because the number of
I'm attempting to build a query that will return all non duplicate (unique) records in a table. The query will need to use multiple fields to determine if the records are duplicate. For example, if a table has the following fields; PKID, ClientID, Na
I have a table like this: .--------------------------------. | Name | XX | Date | .--------------------------------. | N1 | 5 | 2009-05-01 | | N1 | 10 | 2008-01-08 | | N2 | 8 | 2009-02-02 | .________________________________. My result should be this: