sql

MySql calling stored function from within a stored procedure causing error

I'm getting a 1064 error when trying to call a stored function from within a stored procedure. It only happens on the line where I try to do this: SET account_id = get_account_id(user);. What is the problem and how can I fix it? Account ID Stored Functions: CREATE DEFINER=`aaron`@`%` FUNCTION `get_account_id`(user VARCHAR(255)) RETUR...

How to use isset and null variables in functions

I have a fairly simple question I'm guessing. I have the following code at the beginning of my function, but it must not be correct because it causes the blank to turn blank. If I comment out the IF statement, everything runs fine. What am I doing wrong? Sorry, it's probably very basic... function get_entries($order = 'newest', $slug ...

What does the number in parenthesis really mean?

I always thought that the number in the parenthesis represented the field lenght? However, I understand that is not always the case. Maybe it's a mysql issue? Someone told me if I set a field to 9 characters long, I can add a value that's more than 9 characters but only the first 9 will be saved. Example ... create table "person" ( id ...

SQL BETWEEN Operator

Why am I getting '2009' data? What am i doing wrong with the WHERE Clause? SELECT CONVERT(varchar, EventDate, 101) AS EVENTDATE, CONVERT(varchar, ClosedDate, 101) AS CLOSEDDATED, DATEDIFF(Day,EventDate,ClosedDate) AS DiffDate, FROM mytable WHERE (CONVERT(varchar, EventDate, 101) BETWEEN '04/01/2010' AND '04/30/2010')...

Is it possible to create detailed error messages from complex database queries?

Let me illustrate this question with a simplified example. Assume I am building a project using python with a PostgreSQL relational database. In my database I have two tables "parent" and "child" which are N to M related through the table "parent_child". I want to be able to retrieve some data about a specific child owned by a specific p...

Null pointer exception on Execute

I am new to Java (coming from c#) and I am trying to figure out the problem with this code. It should just be inserting a record into a SQL Server database. try { getConnection(true); cstmt = conn.prepareCall("{ call dbo.usp_insert_LeadSubmissionDistributor(?, ?, ?, ?, ?, ?, ?) }"); if (distRepName == null) { c...

Script to save varbinary data to disk

I have some varbinary data stored in a table in MS Sql Server 2005. Does anyone have SQL code that takes a query as input (lets say the query guarantees that a single column of varbinary is returned) and outputs the bytes to disk (one file per row?) I'm sure this has been asked a thousand times before, but Googling comes up with mostly...

What are the [dis]advantages of using a key/value table over nullable columns or separate tables?

I'm upgrading a payment management system I created a while ago. It currently has one table for each payment type it can accept. It is limited to only being able to pay for one thing, which this upgrade is to alleviate. I've been asking for suggestions as to how I should design it, and I have these basic ideas to work from: Have one ta...

propel-gen insert-sql without loosing data?

Is it possible to make propel-gen insert-sql without loosing previous data? Any hack? I usually just add or remove some rows in a table editing schema.xml executing: propel-gen propel-gen sql propel-gen insert-sql and this wipes-out all the data wich is annoying! Thank you! ...

SQL - Most performant manner to conditionally exlude a join? (if it's even possible)

If I have the following table structure... Table 1: BlogPost PostId | Name | Text Table 2: Tags TagId | Tag Table 3: BlogPostTag PostId | TagId And the following stored procedure... CREATE PROCEDURE SearchBlogPosts @tagstring nvarchar(max), AS BEGIN DECLARE @searchTags TABLE (Tag varchar(50)); IF @tagst...

Mysql Recursive Stored Procedure...Limit 0 reached...can't change the max_sp_recursion_depth variable

UPDATE: Ok, I was able to debug this and found that the by doing this select @@max_sp_recursion_depth I can see that the variable is set at 15, however, when I run the call back to itself with CALL single_limb_portfolio_list(xaccount_id, xparent_portfolio_id); I get the error stating the Recursive Limit 0 was reached, but it never iterat...

Duplicate results returned from query when distinct is used

On a current project at I am needing to do some pagination of results returned from SQL. I have hit a corner case in which the query can accept identifiers as part of the where clause, normally this isn't an issue but in one case we have a single identifier being passed up that has a one to many relationship with one of the tables that t...

How to use variables in SQL Reporting 2008 R2

I want to populate a combo box with a list of dates from a DB. Then based on user input I want to be change the Tablix to filter on only dates later than the selected date. How can I do so? Detailed steps will be useful. ...

Help with a seemingly trivial Mysql query with if statements

I've got two fields called T1 and T2 defined as double. I'd like to set T3 with the following conditions: If T1 & T2 >0 then T3=(T1+T2)/2 If T1==0 then T3=T2 if T2==0 then T3=T1 if T1==0 & T2==0, T3=-9999 I have no idea how to include multiple if statements in the query. ...

Inner join - two values that are using the same join!

Hello guys. I have had a good think and just can't get my head around this. I have a table (transfers) like the following id | playerid | old | new | amount They are all integers. I am joining this table (teams) to the following id | name | founded The join is going to be on old and new. old and new are both ints and i need the ...

Instr Function Cognos Report

I am trying to find the @ in a string field. The follow data item in a Congos 8 returns 0 for every call. instr ( [email protected], '@', 1 ) Any ideas? New to Cognos and Oracle in general but I feel like I have to be missing something obvious. ...

Relational modelling question

We have three entities called Product, ProductType, and ProductCategory. Let's pretend we have three kinds of ProductType: Book, Music, and Video. We have three different ProductCategory's for Book: Fiction, Novel, Technical. Three different ProductCategory's for Music: Rock, Jazz, Pop. And we have three different ProductCategory'...

How to pass variable into SqlCommand statement and insert into database table

Hello, I'm writing a small program in C# that uses SQL to store values into a database at runtime based on input by the user. The only problem is I can't figure out the correct Sql syntax to pass variables into my database. private void button1_Click(object sender, EventArgs e) { int num = 2; using (SqlCeConnection...

Can "auto_increment" on "sub_groups" be enforced at a database level?

In Rails, I have the following class Token < ActiveRecord belongs_to :grid attr_accessible :turn_order end When you insert a new token, turn_order should auto-increment. HOWEVER, it should only auto-increment for tokens belonging to the same grid. So, take 4 tokens for example: Token_1 belongs to Grid_1, turn_order should be 1 up...

default value of GUID in for a column in mysql

I want a column to default to a GUID, so if I am doing an insert and I don't explicitly set the value, I want it to default to a new GUID value. how can I do this? ...