sql

Simplify multiple use of same CASE WHEN sequence

This is an under-performing query that I've been trying to simplify but am at a loss. Basically we are looking at Dynamics-SL (Solomon) tables to determine if something has shipped yet or not. Often people enter quantity as having shipped yet the event handling is incorrect as it hasn't actually left the warehouse. So we look at the S...

Performance benefit in this data model ?

I have a MySQL(innodb) table 'items' with the following characteristics Large number of rows, and keeps on increasing. Large number of columns of various data-types including 'text'; primary key 'item_id' is present. There are additional requirements as follows: Need to query items based on their status Need to update status...

How to Script Automatically, the securables assigned to a SQL account

I want to generate script to assign an user account to some securables, e.g. Table:Select. How to do this? ...

SQL "ANSI_NULLS OFF" comparison

I want to check if @a is different from @b in the "ansi_nulls off": set ansi_nulls off declare @a int = 1; declare @b int = null; select case when @a<>@b then 'diff' else 'equal' end '@a=@b ?' --RETURNS 'diff' but without using "set ansi_nulls off". I came up with the following, but it's quite verbose: select case when @a is ...

What is the best way to determine if a timestamp falls within seasonal business hours?

I want a SQL query to check if a given timestamp falls within the open hours of a business. These open hours change depending on the time of year (seasonal hours) and the business is closed for certain holidays. I have a list of these dates, although they are subject to change. What I want is a good structure for storing this informat...

JSON filter (like SQL SELECT)

I have a json file/stream, i like to be able to make select SQL style so here is the file the file contain all the data i have, I'll like to be able to show, let said : all the : odeu_nom and odeu_desc that is : categorie=Feuilles if you can do that with PHP and json (eval) fine... tell me how... on the other part in sql i will do :...

How to get data from multiple tables that belong to fields that contain checkboxes?

Hi, I have a project that makes me confused. I am creating a 2nd hand sale car page for a saler. I have display and edit pages. In edit pages, user will insert a sale car record or edit an existing record. I mean Such a table: RecordID CARNAME Model Year KM PRICE (This Part is ok, easy; but details of car will be showe...

The best online resources for full-text searching in Microsoft SQL?

So I've learned the difference between FREETEXT, FREETEXTTABLE, CONTAINS, and CONTAINSTABLE. And I've created a pretty cool search engine that combines a full-text enabled search with a tagging system (with a little help from you guys). But where have you gone to really learn about and master full-text searching and get the most out of...

Approach to a Bin Packing sql problem

I have a problem in sql where I need to generate a packing list from a list of transactions. Data Model The transactions are stored in a table that contains: transaction id item id item quantity Each transaction can have multiple items (and coincidentally multiple rows with the same transaction id). Each item then has a quantity f...

.net Active Record ORM with full migration support

I'm looking for a .net OR/M that uses the Active Record pattern and allows the developer to define migrations that will update the database scheme in code. I have seen ActiveRecord over at http://www.castleproject.org/activerecord/index.html - but it is poorly documented (with terribly out of date samples) and there is no production read...

What is Mysql select statement to show a list of tables?

I want to write a program that can show the user a list of tables in the database and also show the descriptions of those tables. So can I do a "select * from system_table" or something like that? ...

ORA-01731: circular view definition encountered

we are migrating over to oracle from sql server side. on sqlserver we used to have a view like the following create view blah AS Select column1, column2 FROM blah; but doing this on oracle produces circular view error. is this not allowed on oracle side? ...

Oracle - how to find columns in a table + stored procedures dependent on them?

Scenario: I need to list all the columns in a table1 and all stored procedures that depends on those columns of this table1. I need to populate column name and stored procedures to a new table. I created new_table(col1, sProc) and tried to populate the column name and respective stored procedure on this new_table. Code I wrote is given...

MySQL schema to schema syncronization through triggers?

Quick note: I have 19 days to figure my client's problems out. Background: Client hired a contractor who boasted he could get a new App out the door in 3 months. Two months and some days later I'm brought in and the individual was let go; there is no complete code, no thought put into the schema, and an abomination for a UI. I hav...

How to select the desired result in MySQL?

setup: create table main(id integer unsigned); create table test(id integer unsigned,created datetime,text text); insert into main value(1); insert into test value(1,now(),'something1'); insert into test value(1,now() + interval 1 day,'something2'); Using: select main.id, text from main left join test on main.id=test.id grou...

Can someone please help me with this SQL 08 query? Error when running is....

I am having trouble with the following query which returns the following error: 'Article' is not a recognized option. Incorrect syntax near the keyword 'ON' Is there something obvious wrong that you can point out?? ( @PageIndex int, @PageSize int ) WITH Article AS ( SELECT tbrm_Article.ArticleID, tbrm_Article.CountryID, tbrm_Arti...

PHP MYSQL timeout problem

I have an SQL query like this. When iam executing it though my php file it gives time out error. But when running the same query thoruhg php myadmin it gives results within seconds. SELECT cake_apartments.id, cake_apartments.Headline, cake_apartments.Description, cake_apartments.photoset_id, cake_apartments.Renta...

HTML tags inside the Database - YAY or NAY?

I am using ASP.NET with C# and SQL Server 2005. I have a plane simple ASP.NET label on my form. <asp:Label ID="lblBodyCopy1" runat="server"></asp:Label> On Page load i populate this label with text that is saved in my database. <p class="r_box_A">text text</p><p class="r_box_B">text text text</p> Is this the right thing to do? If ...

What are the strategies for a really fast single table database?

Hello there! I have a database in SQL Server 2008 that supports various applications. I am now starting the development of a new application and, from that database, I require data that fits in one table (though there is some replication). The data I way may be extracted to a view (a few inner joins) with 6 columns. I'm developing a we...

How to reuse sql query result in PHP?

I'd like to do different operations on the data returned from a single sql query, something like this: $sql = "SELECT * FROM mandant"; $res = pg_query($_db,$sql); while ($mandant_list = pg_fetch_object($res)) { # do stuff } while ($mandant = pg_fetch_object($res)) { # do other stuff } But this doesn't work. The fir...