sql

Sql Union Query Help

Hi All, I need a little help writing a query. I have this data... vDir iNumber North 19 North 27 North 29 North 31 South 46 South 49 South 51 South 61 I need to query the data and have an output something like this vDir iLowNumber iHiNumber North 19 27 North 27 29 North 29 ...

Subquery Caching with Sql Server 2008

I am creating a stored procedure with Sql Server 2008 which will return 2 result sets. The first query returns a result set that I would like to resuse as in the second query as a subquery (see example below). However, since the first query and the subquery essentially return the same data, I was wondering if there is some caching meacha...

Is this lookup (association) table correct? (many to many relationship)

CREATE TABLE jokecategory ( jokeid INT NOT NULL, categoryid INT NOT NULL, PRIMARY KEY (jokeid, categoryid) ) DEFAULT CHARACTER SET utf8; especially PRIMARY KEY (jokeid, categoryid)? or is there a better way to write this? Thank you in advance;-) ...

Is it possible to use the Wordpress API (query_posts, WP_Query, get_posts etc) to fetch future posts based on a custom taxonomy?

I'm looking for a way to fetch posts in wordpress that are slated for future publication based on a custom taxonomy query. Finding future posts is otherwise, simple query_posts('post_status=future'); But adding a custom taxonomy doesn't work as expected query_posts('musicians=paul-mccartney&post_status=future'); I ended up using ...

named pipe problem using php to connect ot ms sql 2008

I'm am getting a named pipes error when I try to connect to ms sql server 2008 using a php script running an sqlsrv_connect command. In the ms sql configuration stuff tcp/ip, shared memory, and named pipes are all enabled. Everything is stored on the same server, the database, and the php script so I'm just using a "(local)" for the serv...

How to use Wordnet SUMO using SQL

Is there a way I can use SUMO mappings of Wordnet using only SQL. I am looking for dictionary meanings with formal terms from SUMO as shown in http://sigma.ontologyportal.org:4010/sigma/WordNet.jsp?word=table&POS=1. What SQL queries give similar results ? Thanks of your help. ...

Filtering bad data in SQL Server 2005

Using SQL Server 2005 I have a table with the following columns id name date value I would like to select all rows from the table where there are not four consecutive zeroes by date. How would I do that? Below is an example of what I mean. id name date value 1 a 1/1/2010 5 2 a 1/2/2010...

Cast Stored Procedure Result as a Table? (SQL Server 2008)

Hey all, I currently have a stored procedure that runs a complex query and returns a data set. I'd like to cast this data set to a table (on which I can perform further queries) if at all possible. I know I can do this using a table-valued UDF but I'd prefer to avoid that at this point. Is there any way I can accomplish this task? T...

IDENTITY_INSERT is set to OFF - How to turn it ON?

I have a deleted file archive database that stores the ID of the file that was deleted, I want the admin to be able to restore the file (as well as the same ID for linking files). I do not want to take identity_insert off the entire table, as the increment by one works great. In my insert to TBL_Content store procedure I have somethin...

How can I avoid a deadlock between these two SQL statements?

I have two stored procedures running in separate threads, running on SQL Server 2005. One procedure inserts new rows into a set of tables and the other procedure deletes old data from the same set of tables. These procedures are running into a deadlock on the tables DLevel and Model. Here is the schema: Table DFile: Primary Key = D...

I need help writing a complex (to me) SELECT statement - PHP/MySQL

Ok. I'm new to MySQL have a SELECT statement I can't wrap my head around. I have a table of books with a primary key of ASIN (10-digit ISBN), and I have a table of tags with a auto-incrementing primary key. Then I have a junction table to show which ASINs have which tags associated with them. I can use this SELECT statement to give a...

How to convert newlines (replace \r\n with \n) across all varchar and nvarchar fields in a database

I am recovering from a bug in a system I built where I did not take into account that IE generates Windows-style newlines (\r\n) and other browsers generate Unix-style newlines (\n) when posting HTML forms with text areas. Now I need to convert all Windows-style newlines (\r\n) to Unix-style newlines (\n) throughout the varchar and nvarc...

Most efficient way to do a conditional mysql join on multiple tables? (Yii php framework)

I have five tables: tab_template template_group group user_group user Tab_template's are organized into groups with the template_group relational table. Users's are organized into groups with the user_group relational table. Group's can be public or private (using a tinyint boolean column in the table). I want to query for all of th...

TSQL Dynamically determine parameter list for SP/Function

I want to write a generic logging snip-it into a collection of stored procedures. I'm writing this to have a quantitative measure of our front-user user experience as I know which SP's are used by the front-end software and how they are used. I'd like to use this to gather a base-line before we commence performance tunning and afterward ...

use insert statement into a procedure !

Can i use insert into tables in a procedure (on oracle) ? example: procedure my_procedure (aa1 number ,aa2 number ) is begin insert into lam_table values(aa1,aa2,null) ;(*ofcourse depending on the tables ) ... ... end ; ** note i tried it and it worked but there were a message in the bottom that said (successfully compiled n...

Convert from using 3 identical SQL params to 1.

I'm using the Java spring framework for security. My pre-existing table layout differs from spring's expected, but I'm allowed to specify a custom authorities-by-username query on the jdbc-user-service. The problem is that this query expects only a single parameter (?) in the SQL statement. Basically, if the user exists in the users t...

SQL SSIS Help. Import an excel sheet into a temp table.

I have a farily simple task of taking an Excel sheet and importing it into a SQL 2005 database table. I need to create an SSIS task for this. The Excel sheet does not have all the columns I need to make the insert directly into the permanent sql table, but I know how I could link out to other tables and get the columns that are missing...

PL/SQL: SQL Statement ignored

I have the following small function that does not compile: function f_query_01 Return interval Day to second is start_time timestamp(3); end_time timestamp(3); time_diff interval Day to second; c_query_number number; begin start_time := systimestamp; select count(*) into c_query_number from wg; <--This is the line th...

For XML length limitation

Hi I am trying to concatenate results of some string data in a query using XML PATH See query below.What happens is that the XML concatenated column statement gets truncated.Seems like there is a limitation on maximum length.How do I overcome this. select SUBSTRING(statement,1,len(statement)-2)+';' from( select 'update '+tab.table_na...

How can I speed up queries against huge data warehouse tables with effective-dated data?

So I am querying some extremely large tables. The reason they are so large is because PeopleSoft inserts new records every time a change is made to some data, rather than updating existing records. In effect, its transactional tables are also a data warehouse. This necessitates queries that have nested selects in them, to get the most...