sql

SQL joining question

Here is my situation: I have one table that contains a list of drugs sold containing the NDC (an identifier), quantity sold, and whether the drug is a brand name or generic. I have another table that contains the prescription numbers, dates, and NDCs. I need to generate a list of the most recent 4 prescription numbers for the top 50...

Can I use a MySQL database with an App Engine application

I know that App Engine has its own datastore. This is great for most cases and fairly easy to used. However, we have a MySQL database that we use for several applications and not all of them are Web based. We want to use App Engine for many reasons, but would like to have the App Engine application access our MySQL database. The document...

T-SQL: Concept similar to C# params

Does T-SQL allow a variable number of arguments to a stored procedure like params in C#? EDIT: I'm using SQL Server 2005. That 2008 answer makes me wish we were using it... ...

MySql query is to slow. `Join Tbl AS t ON t.c = t0.c`

My supervisor told me this query will 'crash the server' (because it has millions of tables i believe). Can anyone tell me WHY? maybe show me the way i am suppose to do it? I am currently reading manuals to figure this out. What i was told is these joins are to slow. What is slow about it? "JOIN A AS o ON a.A =aa.A " . "JOIN B AS...

SQL 2008 Dictionary Data Compression - is this only for WHOLE column matches?

For simplicity suppose I have one varchar(50) per row and these are my rows: 1) The quick brown fox jumps over the lazy dog 2) I like brown foxes 3) fox 4) fox So the page compression would find the word fox for instance and put it in the dictionary. Would only rows 3 and 4 benefit and rows 1 and 2 would not because they contain other...

sql server trigger

I have a table structure like this: create table status_master ( Name varchar(40) status varchar(10) ) I need to create trigger for status column if the status column value updated value FAIL then the trigger invoke one insert commant like: insert into temp value('s',s's') Could you please any one give me tha idea to solve this...

Executing an Oracle Stored Procedure from SQL Server 2005

how do we execute an Oracle Stored Procedure from SQL Server 2005? As part of a SQL Server scripts we need to execute an Oracle 10g Stored Procedure and download data to SQL Server 2005 ...

SQL Server 2005 Outer Join Problem In Stored Procedure

Good Afternoon All, I have two tables in my SQL Server 2005 DB, Main and MSDRGWEIGHTS. I want to create a stored procedure that updates Main.RelWeight with the appropriate value from MSDRGWEIGHTS. I have written the following code as part of the stored procedure: UPDATE MAIN left outer join MSDRGWEIGHTS AS W ON MAIN.MSDRG=W.MSDRG SE...

Collapse Blank Columns For Each Row

I have a large table I imported from an Excel spreadsheet. For five of the columns, containing teacher names, I'd like to collapse all of the blanks in each row so I have no blanks to the left of any name. An example would probably show better what I mean. Here's an example of the data now: Student ID Teacher1 Teacher2 Teacher3 Tea...

MySQL remove duplicates from big database quick

Hello, I've got big (>Mil rows) MySQL database messed up by duplicates. I think it could be from 1/4 to 1/2 of the whole db filled with them. I need to get rid of them quick (i mean query execution time). Here's how it looks: id (index) | text1 | text2 | text3 text1 & text2 combination should be unique, if there are any duplicates, only ...

Insert value to another sqlserver db

I have 2 SQL Servers: temp1 XX.13.23.2 temp2 XX.23.45.6 The temp1 server has a database called db1 and contains a procedure called p1. I want that procedure to insert the value on Temp2 server Database name db2 on table T1. Is it possible to use procedure to insert value on another server's database? If this is this possible th...

MySQL Default Keyword usage errors

When am trying to set default date and default sysdate am getting following errors: MySQL Query: create table product_offer_type(object_id INT(19), snapshot_id INT(19), PRIMARY KEY(object_id,snapshot_id), enum_value VARCHAR(64) NOT NULL, external_name VARCHAR(64) NOT NULL, description VARCHAR(255), business_validation INT(1), valid_for...

how to make procedure that update 5 table's ?

How to make procedure that update 5 table's ? for ex: ....update table1 set field1 = ....... ....update table2 set field2 = ....... ....update table3 set field3 = ....... in oracle 10g - pl/sql ...

Sql Server Management Studio - Programatically Creating Scipts based on DAL; Why use SET ANSI_NULLS ON before each table

I'm looking to generate the SQL scripts for table creation programmatically based on class definitions in my DAL similar to SQL Server Management Studio. So, when I right click on a table in MS SMS, and tell it to script table as > Create to > new query window, it generates some very understandable code. However, I'm not sure why the...

Mysql query. What is the difference between Join and a SubQuery?

I always though join gets the results of something and then joins only using those results. SELECT * FROM tbl AS t1 JOIN tbl2 AS t2 ON t1.id = t2.foreignId JOIN tbl3 AS t3 ON t2.id = t3.foreignId WHERE t1.date > SOMEDATE From my understanding it will run the where statement and get only the results that fall within the date range. Th...

MySQL Count values based on multiple columns

I have two tables: a 'userlist' that has a 'grade' and 'userID' columns, and a 'login' table that records each time a user is logged in. The login table has a 'userID' column that is associated with the 'userID'. This login table has a row inserted into it each time a user is logged in, so if a user logs in three times, three rows will b...

In SQL, can i convert a "|" separated list of IDs to a list of their values?

Using states as an example, my current data looks like StateAbbrev | NumOfResults ----------- ------------ MD | 5 VA | 2 DC | 7 MD|VA | 2 CA|NY|VA | 1 I would like it to output the following StateName | NumOfResults --------- ------------ Maryland ...

sql Query Issue

Hello experts, I have a table as shown below Q_ID DeptID EmployeeName City 100 100 testest abcd 100 101 tata cdd with 100K records. I need a query which should fetch all records with same Q_ID but different DEPTID. Please help. Thanks ...

SQL query generator for Perl with stored procedures support

Current code base I'm working on is full of ad-hoc conditional string concatenations producing less than clear SQL queries. I want to make them maintainable, but since using DBIx::Class is too complex to move to for now (giant legacy base), I'm looking to at least make them more robust by using some sort of SQL generator, which would onl...

Can I use wildcards in "IN" MySQL statement?

I would like to run something like: select * from table where field in ("%apple%", "%orange%") Is there a way? Or at least is there a better way than dynamically building query for every keyword: select * from table where field like "%apple%" or field like "%orange%" Thanks. ...