sql

LINQ-to-SQL Enumerable expression with Binary = null fails

This is a strange LINQ-to-SQL problem which can't evaluate as an Enumerable (in SQL) but I can evaluate client side. I think it's related to my testing Binary property as 'null'. I need to determine when my Job is complete, which means that all Files in that Job have at least some data in their binary FileContents property. The proced...

select latest entry per day and corresponding data

I have a table in SQLite: CREATE TABLE test_results(timestamp TEXT, npass INTEGER, nfails INTEGER) I want to return the last pass/fail information for each day. For example if the table contains... 2009-08-31 23:30:19|0|24 2009-08-31 23:37:18|0|24 2009-08-31 23:40:00|0|24 2009-09-01 19:02:13|0|2 2009-09-01 19:08:24|2|0 2009-09-01 1...

Given a date, how to get next and previous date in database

I have a database with a bunch of dates. I would like to, given a date, get the next date in the database and previous date in the database. So given a databse with 10/10/09, 10/12/09, and 10/15/09, if someone enters the date 10/13/09, it should return 10/12/09 as the previous date and 10/15/09 as the next date. How can I do this? Than...

How to do this Transform for millions of Rows

Input : Pairs of From->To Rows. From To 1 2 2 3 3 4 6 7 Output: For Each From Value, pairs of reachable To values. E.g. for 1 Source Reachable 1 2 1 3 1 4 Obviously, one can suck out the data to a Graph structure and run DFS scan. Is there a alternative way to do so, such that: Uses SQL/Fu...

best way to migrate tables from MS access to sql server and consolidate

I have a ms access database that has one table for each photo album with the name of the table as the albumname tablename = "Trips" fields: picID, comment i am migrating to sql server and i wanted to fix this normalization issue and just have One table called Albums with albumID and albumName One table called pictures with picID, alb...

Selecting a range of rows using 3 different indices

My database looks like this: Book,Chapter,Verse,Scripture "1","1","1","1text1" "1","1","2","1text2" "1","1","3","1text3" "1","1","4","1text4" "1","2","1","2text1" "1","2","2","2text2" "1","2","3","2text3" I want to select all the rows from 1,1,1 to 1,2,3. However my current query will not return row 1,1,4 because 4 is greater than 3....

Sql ELSE case is not working

I have below query I am trying to show message 'No SubSource for this RAO' when there is no 'tblOrganisation.Name', please have look into below query, it working fine but not showing my message when there no organisation.name returned DECLARE @RAOID INT, @ORGID INT SET @ORGID = 28 SET @RAOID = (SELECT RAOID FROM tblOrganisation WHERE O...

selecting rows from sql server where a casting issue occurs

Hi everyone, i was just wondering if anyone knows how to select rows where a specified column will come under a casting issue. ie. SELECT * FROM ThisTable t WHERE 0 <> ( select cast(t.value as datetime) ) the 'select cast(t.value as datetime)' would ideally return the result of @@error to indicate the casting issue has oc...

Select Count Distinct

I would like to count the number of installations of each Member in a table similar to this. But this count distinct drives me nuts... MemberID | InstallDate 1 | Yesterday 2 | Today 1 | Today 3 | Today The above table should produce something like this one.. MemberID | CountNumberOfInstallations 1 | 2 2 | 1 3 | 1 p.s. I know...

CakePHP: Numbered Paginated Results

The title is a bit wonky but it's the best I could come up with at 4 in the morn'. I have a table of links that I am paginating, nothing fancy. Let's say there are 100 links that are displayed 20 a page for 5 pages. How can I number each link starting with 1 and ending with 20 on the first page and if we skipped to the last page would...

rails average between multiple models

I've been trying to get my head around doing things using my Rails relationships as opposed to pulling out large SQL joins, but I can't wrap my head around this one... I have 3 models Hotels Rooms Availables They all have the appropriate has_many and belongs_to relationships. What I want to do is on the overview page listing th...

View with Full Outer Join

I want to create a view from the following two tables: Entry: entry_id entry_date entry_amount user_id Forecast: forecast_id forecast_date forecast_amount user_id Now I want to have a view which combines each entry with its forecast (same user_id and same date). This is fine, but I have a problem with those rows, which have a forecas...

SQL Update varchar to date error

Hi I have a table with 5 million records of dates stored as char(10) with format yyyy/mm/dd. I need to convert these to datetime, so I use: UPDATE [Database].[dbo].[Table] SET [DoB]=convert(datetime,[DoBText],103) GO But I get the error: "The conversion of a varchar data type to a datetime data type resulted in an out-of-range...

Cumulative sum in mysql view

I have a table holding values for each month of different years. Entries: entry_id entry_date entry_amount Now I want a view which holds all entry values, and the cumulative sum of the current year's amounts. Entries_sum_view: entry_id entry_date entry_amount entry_cumulative_yearly_sum where entry_cumulative_yearly_sum = SUM(all e...

How to sort sql result using a pre defined series of rows

i have a table like this one: -------------------------------- id | name -------------------------------- 1 | aa 2 | aa 3 | aa 4 | aa 5 | bb 6 | bb ... one million more ... and i like to obtain an arbitrary number of rows in a pre defined sequence and the other rows ordered by their name. e.g. in another table i have a short seq...

How to export image field to file?

Hi, I am using Microsoft SQL Server Management Studio to connect to a database. In it I've got a table, one column of which is an Image column containing file data. Another column is a string containing the file name. Is there some way I can write some sql script that will allow me to select a record and write this data to a file? Or i...

Does SqlCommand optimize parameterized sql statements?

I know in Java, when using PreparedStatement with parameters, some JDBC drivers will optimize the SQL queries by turning them into stored procedures so that all the subsequent calls will run faster. Does SqlCommand provide such optimization when accessing MS SQLServer? ...

need to create a proc or anonymous block

hi, we have one table as following Table name: metadata_table strucutre is as follows S.No Tablename Column 1 Fct_sales_summary wk_units 2 Fct_exp_summary mn_units wk_units as in the table Fct_sales_summary are columns and are in range wk_units1 to wk_units105 and similarly in Fct_exp_summary ...

How do I find out if an oracle database is set to autocommit?

And while we're at it, how do I switch between autocommit and non-autocommit? ...

Django: retrieve all galleries containing one public photo at least

Hi (please, excuse me for my ugly english) ! Imagine these very simple models : class Photo(models.Model): is_public = models.BooleanField('Public', default=False) class Gallery(models.Model): photos = models.ManyToManyField('Photos', related_name='galleries', null=True, blank=True) I need to select all Gallery instances whi...