Excel VBA - Execute an SQL stored procedure error

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

Apply uniqueness to a subset of rows on a table in Oracle DB

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

How can I get the account of men and women count separately

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',

SQL Server - update the table one record at a time

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

SUM does not display the expected value in SQL

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

Simple Trigger on Salary

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

PL SQL loop through the ID list

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

Table Values ​​Sql in JSON C #

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

How to use an SQL subquery?

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

select N items for each group?

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

how to convert the date to a format `mm / dd / yyyy '

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

MySQL: Produce a list of people who have more than one object

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

get data from the table where a field is maximal in a query

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

Rewriting an ORACLE SQL statement

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

join two tables to be linked on a gridview

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| |-------|---

MySQL parent details if it is a child account

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

Counting the number of rows displayed in a table in Access

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 -

A query to display pairs based on certain conditions in a join

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

MySQL Query - Add Columns & amp; rows

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

Total sum of two requests

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

Database Design - Multiple Multiple Relationships

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

SQL nested queries

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

Distinct with select *

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

SQL query for non-duplicate records

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

Mysql query with group by and order by

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: