sql

Is it possible to structure a SQL query to automatically create a table if it doesn't already exist?

I'm a complete SQL novice, and I'm trying to accomplish the following (pseudo-code) with a single query: if (a table named "config_data" does not exist) { create a table named "config_data" } if ("config_data" has no rows) { add a row to "config_data" with some default data } return all rows in "config_data" How would I go about it?...

run sql script from shell script

I have the below shell script that calls an sql script. The problem is it calls the sql script, i enter the username,password ,dbname and after that it creates the table but it doesn't exit from the sql prompt. test.sh #!/usr/bin/ksh sql_test=test.sql $ORACLE_HOME/bin/sqlplus /nolog @${sql_test} exit test.sql CONNECT &&usr/&&pa...

PostgreSQL 'Deferrable Delete' still hits constraint on Delete

I want to delete rows from two tables which have a dependence upon each other through a set of deferrable constraints. To simplify this post, I've mocked up a simple DB schema. I'm hoping to remove entries from some table, 'delete_from_me', inside a SQL transaction/DB Patch. The catch is, I want to delete based on a select from a second...

Call aspnet_regsql.exe from SQL script

Hello, how to call aspnet_regsql.exe from an SQL script? thanks ...

Optional parameter in SQL server

Hi, I have a user defined function which is used in many stored procedures which will return me some value. If it possible for me to add a new optional parameter to the same. If I don't pass any value it should be null and if I pass some value it should take it. I don't want to go and change all the stored procedures to do so. Example...

Title: Multipart identifier s.Company_id could not be bound

I am getting the following error while executing the query . Please help Multipart identifier s.Company_id could not be bound INSERT INTO Company_Item_Company_List ( Company_id, Company_item_id, client_id, last_modified_timestamp, last_modified_user_id ) SELECT dcsl.distribution_center_id, sisl.Compan...

Searching Technique in SQL (Like,Contain)

I want to compare and select a field from DB using Like keyword or any other technique. My query is the following: SELECT * FROM Test WHERE name LIKE '%xxxxxx_Ramakrishnan_zzzzz%'; but my fields only contain 'Ramakrishnan' My Input string contain some extra character xxxxxx_Ramakrishnan_zzzzz I want the SQL query for this. Can any ...

strip all spaces from column in mysql?

hi there, i have a table that has 'number' 1234 12 34 1 2 34 1 2 3 4 ect... so, im wondering how can i write a query that will remove all spaces? something like update `table` set number = REPLACE( ' ', '', (select 'number' from `table`)); is there anything that will do this? ...

How to: SQL or NOSQL?

I haven't been confronted with this yet, but this is what i think (very superficial and simplistic imho) If you have a key value kind of storage and all you accesses are key lookups use the NOSQL solutions. If you want lookups based on values (and subvalues) or have something more complicated like joins you would go for a relational sol...

Direct database connection vs Web Service, for MySQL+SQL eCommerce integration?

Hi, I need to integrate orders from an online eCommerce site (Linux/PHP) into a client-server system (.Net/MSSQL), as well as checking stock levels and products from the client-server side into the eCommerce site. I found these answers, but they don't satisfy me. The MySQL database is not exposed publicly, while the MSSQL database is. ...

How to use MYSQL's "AS" returned value inside WHERE clause?

I have a query like below... SELECT contents.id, contents.title, contents.createdBy, (SELECT userGroup FROM suser_profile WHERE userId = (SELECT users.id FROM users WHERE login = contents.createdBy) ) as userGroupID FROM contents WHERE contents.id > 0 AND c...

C# SQL query exception

I'm using C# in .NET 2.0 and I'm trying to access and manipulate a database. I can read as many times from the DB as I want and everything works, but as soon as I try to insert an item I get the following error message: ExecuteNonQuery requires an open and available Connection. The connection's current state is closed. I've tried to l...

How to select a particular Node name in XML using Oracle SQL query?

I need to select a particular Node name in the XML file using sql string? Sample XML structure <Root> <Body> <Car> // This can be "Bike", "ship", "Train"... ect <name value="figo"/> </Car> </Body> </Root> I want to run a query which which will fetch what Node name is present in XML "car" or "Train" or "Bi...

Why are SQL entries written in uppercase?

Possible Duplicate: Why should I capitalize my SQL keywords? hi, I'm pretty new to SQL, but i've noticed that writing SELECT * FROM column_name is almost always used when select * from column_name yields exactly the same result. I can't find anything online about this. Is this just a convention? Or will not using uppe...

Adding new columns to a column database having billions of rows.

I want to add a new column to a table which already consists billions of rows. The new columns are derived from existing columns. For example, new_col1 = old_col1 + old_col2 new_col2 = old_col1 / old_col2 I am trying to do this in following way - Add new columns ALTER TABLE table_name ADD ( column_1 column-definition, colum...

What is wrong with this SQL?

I'm sure this is something really simple that I'm overlooking, but MS SQL is new to me -- I am (or at least thought I was) fairly comfortable with basic MySql though. SELECT l.link_id, l.link_allcount, d.desc_id, d.desc_count, d.desc_text, h.hour_17, dl.day_19 FROM lnktrk_links AS l, lnktrk_hourly AS h, lnktrk_daily AS dl LEFT JOIN ...

sql crosstab problem

Here's the very detail prob: this date belongs only to 1 table custcode address cust1 capitol, cebu city cust1 gen. maxilom, cebu city cust1 guadalupe, cebu city cust2 paknaan, mandaue city cust2 basak, mandaue city cust3 lapu-lapu city In my report I want to have this fields in my reportviewer customer nam...

How to create this SQL constraint.

The situation I am in is that I have a set of existing tables with incrementing Integers as Ids. I have now added a GUID to each table to be the new PK. I have a primary table dbo.ParentTable(GUID - PK, ParentTableId INT, Name VARHCHAR) and a child table dbo.ChildTable(GUID - PK, ParentTableId INT, other fields.....) and want ...

Tracking user-actions in a ASP.net data access application

I need to log every user-action taken on a database using the username of the person logged into my ASP.net application as the identifier in the log. What is the easiest way to do this? I guess that for every method call to my data access layer I need to log the parameters of that call and the username and then call a new "log event" m...

Creating a simple join on a table with django

Hi, I have a data model in django called MainData which was created on top of a table called "my_data". I want to perfom a simple calculation on top of this table via django API. The query is as follow: select main.id, sum(main.num - secondary.num) as result from (select * from my_data where some_value >...