sql

Is It Possible to Add SQL Reporting Service to SQL Server 2008 Express?

I joined a windows host who runs SQL Server 2008 Express (Negative Surprise)! I think this is wrong since a host should expect some medium companies join them so they should put at least standard version. I don't know much about dba, but this is my suggestion. Am i right? OK! Here is my question, the host has SQL Reporting Service as an...

How to select a column in SQL Server with a special character in the column name?

I have a table contain the '%' in the column title, and this cause problem when I do the select statement on that column (Find below for more details). Does anyone know how can I select that column by not keeping the original column title? Example: Table1 name ref_no tot_sales %Phone ------------------------------- Alan 1 1 ...

JDBC general query execution

Is there a way, in JDBC, to execute a generic query ? I mean run something like execute(String strSql) where strSql could be a SELECT, an INSERT, an UPDATE,a CREATE,... or whatever. If no, how would you fix this up ? Proposed solution: @Override public void execQuery(String Query) throws SQLException { this.statement = this.connec...

Best data type for storing strings in SQL Server?

What's the best data type to be used when storing strings, like a first name? I've seen varchar and nvarchar both used. Which one is better? Does it matter? I've also heard that the best length to use is 255, but I don't know why. Is there a specific length that is preferred for strings? ...

mysql left join ascending

I have a query: SELECT reply.id, reply.message, reply.userid, reply.date, medal.id, medal.url, medal.name, user.id, user.name AS username FROM posts AS reply LEFT JOIN users AS user ON reply.userid = user.id LEFT JOIN medals AS medal ON medal.userid ...

SQL Prepared Statment to Create Table

I wanted to know of some way to create table on the fly based on user input(SQL Prepared Statement) CREATE TABLE ? ( First_Name char(50), Last_Name char(50) ) What should i put in place of question mark ...

Two left joins and a union in MySQL

I'm trying to do a pretty complex query in MySQL; complex for me, at least. Here's an example of what I'm trying to do: SELECT * FROM friends LEFT JOIN users ON users.uid = friends.fid1 LEFT JOIN users ON users.uid = friends.fid2 WHERE (friends.fid1 = 1) AND (friends.fid2 > 1) UNION SELECT fid2 FROM friends WHERE (friends.fid2 = 1) AN...

Importing .sql file into my database inputs them out of order

I am using phpadmin and I exported a .sql file to backup my database. When I went to import the .sql file it imports the rows in the wrong order. Is their anyway to remedy this problem? ...

PHP PDO fetch error. rowcount = 1 but fetchall returns false;

i ave been having trouble with a simple select sql query. using php PDO. for some reason the rowcount returns 1 but fetch and fetchall both return false; to me that means the execute failed or the query returned no results which would have a rowcount of 0. my sql syntax as far as i can tell is fine. here is the sql query SELECT * FROM...

The used SELECT statements have a different number of columns (REDUX!!)

There's another question out there similar to this, but it didn't seem to answer my question. My question is this: why am I getting back this error ERROR 1222 (21000): The used SELECT statements have a different number of columns from the following SQL SELECT * FROM friends LEFT JOIN users AS u1 ON users.uid = friends.fid1 LEFT JOIN u...

SQL Server version of Oracle's CONNECT BY in LINQ to show hierachy

I have successfully simulated an Oracle CONNECT BY statement in SQL Server 2008 by following these 2 previous answers here and here and adjusting to get the results I need. But how do I do this in LINQ? Here is an example of what I am doing using a dummy database: CREATE TABLE Employee( EmployeeID INT IDENTITY(1,1) PRIMARY KEY, Depar...

Different faces of COUNT

I would like to know the difference between the following 4 simple queries in terms of result and functionality: SELECT COUNT(*) FROM employees; SELECT COUNT(0) FROM employees; SELECT COUNT(1) FROM employees; SELECT COUNT(2) FROM employees; ...

Insert ...on duplicate in oracle?

Hi, I am new to Oracle and I want to check if particular primary key value is present or not. If value exists then just update the entire row .If value is not present, then insert new row. INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1; Code above works on MySql. How to achieve the same in Oracle 10g? Can an...

How to delete rows in tables that contain foreign keys to other tables

Suppose there is a main table containing a primary key and there is another table which contains a foreign key to this main table. So if we delete the row of main table it will delete the child table also. How do I write this query? ...

Unable to generate my report

I have to generate a report in this format: staffcode Name dateintime dateoutime duration for example: Staffcode Name 01-08-2010intime 01-08-20100uttime 01-08-2010duration 1001 Amit 09:00 18:30 09:30 In sql server management studio for 5 days i have ...

inadvertent sql queries?

Wordpress bug. My blog post contains the sentence fragment "...semantics, and selection are embodied processes that emerge naturally from the world itself". Wordpress responds to my attempt to save the draft with a 'post not found' error. If I delete this fragment, the error goes away. I'm thinking that Wordpress is interpreting this as...

conditional update on same column

Hi Pl find code below SQL> desc aaa Name Null? Type ----------------------------------------- -------- ---------------------------- ENAME VARCHAR2(1) SQL> select * from aaa; E - 2 2 2 5 5 5 5 7 rows selected. I need to update 2 with 5 and 5 w...

SQL Server: how to use the same procedure in different instances?

I have a stored procedure in a test instance of a sql server (named sql2008test\sql2008_test) and it is located in one database. I would like to use this procedure also in production instance (named sql2008prod\sql2008_prod). Should I copy this procedure into this prod instance or can I modify my procedure somehow to query data from prod...

Any free tool for SQL server log recovery<SQL 2005)

Hi, By mistake I have updated all the rows of a table with same data for certain columns (missed the statement that contains where clause). Are there any free tools that can help me to restore old data for these rows. ...

How does Oracle process stored function calls in SQL?

Hi, guys. Say, I have a query: select t.value, my_stored_function(t.value) from my_table t where my_stored_function(t.value) = n_Some_Required_Value I have rewritten it in the following way: select value, func_value from (select t.value, my_stored_function(t.value) func_value from my_table t) subquery where subquery....