sql

How do you export all tables to a CSV file using SQL Management Studio?

When I right click on the database I want to export data from, I only get to select a single table or view, rather than being able to export all of the data. Is there a way to export all of the data? If this is not possible, could you advise on how I could do the following: I have two databases, with the same table names, but one has ...

How to formulate conditional expression in SSIS Data Flow tab?

I am developing an SSIS 2008 package and I am trying to create a Derived Column transformation. But when I go to the Expression editor and try this expression it gives me alot of errors. I have tried various differentiations of this but all have resulted in errors. I need one of you SQL experts to point out a better expression! IS...

SQL Server Database Restore with ReadXML

I've backup from a sqlserver created with this procedure: protected void WriteXML(string tableName) { using (SqlConnection cnn = new SqlConnection(ConnectionString)) { using (SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM [" + tableName + "];", cnn)) { cnn.Open(); DataSet ds...

Help with a SQL query with a couple of foreign keys.

I have the following tables structure: Shipment (has IDDestination as foreign key) -> Destination (has IDCity as foreign key) -> City (has IDCountry as foreign key). I want to give my stored procedure a Country ID and have it return all of the shipments. How would I do this with pure SQL syntax? I could do this trivially with an ORM, b...

MySQL how to fill missing dates in range?

I have a table with 2 columns, date and score. It has at most 30 entries, for each of the last 30 days one. date score ----------------- 1.8.2010 19 2.8.2010 21 4.8.2010 14 7.8.2010 10 10.8.2010 14 My problem is that some dates are missing - I want to see: date score ----------------- 1.8.2010 19 2.8.2010 21 3.8.2010...

nested SQL Stored proc while not looping

I am trying to generate a set of rows for a matrix but the @xcolcount only does on loop staying at zero while the inner loop does what it needs to: Declare @xColCount int Declare @yRowCount int set @xColCount = 0 set @yRowCount = 0 WHILE (@xColCount < @widthCol) BEGIN WHILE (@yRowCount < @heightRow) BEGIN -- do the i...

Is there a better, SQL way to do this Ruby's Array.delete_if with a Rails.find request?

Hi, I have a Tag object (id, name) and a Tagging object (id, tag_id, type). I want to find all the tags that have a name like "kevin" and for which I can find a foreign Tagging object with type set to "people" (type can be set to people or some other tagging stuff). I tried with a complex SQL request in a Rails Tag.find method but didn...

django-signals vs triggers?

I read about django signals (http://docs.djangoproject.com/en/dev/topics/signals/), but as far as I understand, signals are never converted into literal SQL triggers (http://en.wikipedia.org/wiki/Database_trigger). If I'm correct that signals and triggers are different, then which one is better and in what ways? What's the best practice...

Oracle sql query to show count of events daily and total number of events for last seven days

There is the following table: event_table, which contains information about object_name, event_number, event_supplementary_info, event_time. I would like to have a sql query, which shows number of events per last seven day daily and total number. I need something like this select Object_name, event_number max(decode(trim(dow),'MONDAY'...

Dynamic SQL within cursor

My dynamic sql below to alter a table & create columns based on the output of a query is giving error. Query : DECLARE CURSOR c1 is select distinct WP_NO from temp; cnum VARCHAR2(255); BEGIN FOR cnum in c1 LOOP EXECUTE IMMEDIATE 'Alter table temp_col add (:1 varchar2(255))' using cnum; END LOOP; COMMIT; END; ...

help with a sql query joining 2 many-many tables

i want help how to solve this sql problem. suppose i have 3 tables Movie ID Name Genre ID Name Movie_Genre (this one is the link for many to many) FK_MovieID FK_GenreID i want to select all the movies that are of genre 1 and genre 3 how is this possible? i can only select the movies of 1 genre but not the movies...

Mysql fetch array error.

Im getting an error on my site that appeared for the first time today, despite functioning fine for months. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /web_directory/index.php on line 33 Here is the code from those lines. <? $sql = "SELECT p.id as 'id', p.post_...

Mysql Select record based on last run

I have a table which has following fields project_name VARCHAR (100) running_frequency enum ('daily', 'weekly', 'monthly') last_job_run DATETIME I want to select those records which are due now based on last_job_run field. For instance, if a task has run yesterday and daily is selected then I need a query to select the re...

Tips on writing SQL for multiple databases

Different databases have differences in SQL support & implementation. Sometimes there is a difference in SQL syntax, sometimes support for some SQL commands is missing, sometimes the database has a feature that other databases do not have. What are considered to be good practices in writing SQL queries that are good for different databa...

SSIS Help : How to Send Email if invalid Records Found from a query

Hi Guys, I need your help. I have a query below. i wanna use this query in SSIS package which would run every week. All this query doing is, truncate table PlanFinder.InvalidAwps and load it with new Invalid records. Now, how do i use this query in SSIS package to send email if any invalid record found in invalidAwps table. i can use Ex...

Selecting the highest salary

Assuming a wagetable: name lowhours highhours wage Default 0.0 40.0 100 Default 40.0 50.0 150 Default 50.0 70.5 154 Default 70.5 100.0 200 Brian 0.0 40.0 200 Brian 40.0 50.0 250 Brian 50.0 60.0 275 Brian 60.0 7...

Best way to store tags in a database?

I have a database that contains two tables: entries tags The entries table contains posts that each have one or more tags. The problem is, each post can have any number of tags. In other words, I can't have a 'tag1', 'tag2', etc. column and do a LEFT JOIN. How should I set up entries so that each post can have any number of tags? ...

What's the R equivalent of SQL's LIKE 'description%' statement?

Not sure how else to ask this but, I want to search for a term within several string elements. Here's what my code looks like (but wrong): inplay = vector(length=nrow(des)) for (ii in 1:nrow(des)) { if (des[ii] = 'In play%') inplay[ii] = 1 else inplay[ii] = 0 } des is a vector that stores strings such as "Swinging Strike", "In pla...

SQLite: Combining an OR and AND

This is continuing questions from http://stackoverflow.com/questions/3539673/sqlite-selecting-the-highest-salary Assuming a table 'wagetable' name lowhours highhours wage priority Default 0.0 40.0 100 0 Default 40.0 50.0 150 0 Default 50.0 70.5 154 0 D...

Foreign key constraint that points to one of several tables

I have a table with one column source_id whose value should be the primary key of another table, though which table it is will vary from record to record. Every record must have a value for source_table that specifies the table for the source record, and a value for source_id that specifies the row in the source table. Is there any way ...