I want to get a list of the field names returned from a sql statement. This can be done using a sql statement or some c# parsing code to parse the statement as a string. Can this be done easily without writing a complex parser?
For example I may want to return
name, field2, field3
from
SELECT a.field1 as name, a.field2, b.field3 FR...
I have this simple query that works on all other database systems, but fails with MySQL:
UPDATE points p
SET p.userid = 5224
WHERE p.userid = 2532
AND NOT EXISTS (
SELECT 1
FROM points q
WHERE q.userid = 5224
AND q.game = p.game
)
I get the following error message:
#1093 - You can't specify target table 'p' for up...
I have a database student(attribute - studentid). studentid is a varchar. Now I want to add 'P' at the end of all studentids.
12 -> 12P
234 -> 234P
What will be the sql query for this?
...
I have this db with lots of tables and frequently I have to answer the question: Why is entry x not being shown?
Often I have an idea which entry might be the reason, but more often its wild guessing and trying.
This gets boring after some time. Is there a tool out there where I enter the joins and the key of the entry that I want to ...
Where clause:
I should test column against value in Proc, but if at least one of them is null it should be TRUE as a result. Only when BOTH NOT NULL (it's Integer values for an ID column in a table) should the result of the compare be FALSE.
Now I have this:
...
and nvl(nvl(b.account_id, account_id_), 0) = nvl(nvl(account_id_, b.accoun...
Consider two table.Employee and Project.Employee table has fields like eid,ename.Project table has fields like pid,pname.Now,since an employee can work on many projects and a project can be done by many employees, therefore,as evident,there is a many to many relationship b/w the two tables.Break the many to many,and create a new table ca...
Hello,
I have 3 tables: people, groups and memberships. Memberships is a join table between people and groups, and have 3 columns: personId, groupId and description (text).
I want to select entries from the memberships table depending on a groupId but sorting the result by the names of people associated to the found memberships (name i...
What´s the name of the behavior in the statement below?
Create table dbo.Foo(name varchar(10))
insert dbo.Foo (name)
select 'Weird'
union
select 'SQL'
union
select 'Server'
union
select 'behavior'
declare @title varchar(max)
set @title = ''
select @title = name + ' ' + @title from dbo.Foo
select @title
--returns 'Weird SQL Server b...
Are there any best-pratices/patterns or general advice for partitioning large amounts of hierarchical data?
Think of, say, a database of all the people in a given country and tracking who has worked with who. Thinking of the "person" entities in isolation, if a lot of data were to be kept about each person then a natural approach seems...
Let's say I have the following table:
ID | parentID | MoreStuff
1 | -1 | ...
2 | 1 | ...
3 | 1 | ...
4 | 2 | ...
5 | 1 | ...
How can I generate an SQL SELECT statement to find out if a specific row has children? In other words, I want to know if ID 1 has children, which in this case it has 3...
I'm pretty new when it comes to PL/SQL, and I have to modify someone else's stored procedure.
Is it possible to add an if statement in the middle of a select? The procedure I have tries to open a cursor and select a bunch of stuff from different tables into it (don't ask me why they didn't use a join) and return the cursor. The thing ...
Hello.
I need to sync two PostgreSQL databases (some tables from development db to production db) sometimes.
So I came up with this script:
[...]
pg_dump -a -F tar -t table1 -t table2 -U user1 dbname1 | \
pg_restore -a -U user2 -d dbname2
[...]
The problem is that this works just for newly added rows. When I edit non-PK column I get...
Please take a look at the following table (called response). It shows what response a respondent has given to a question and answer.
questionid answerid respondentid
1 10 1
1 11 2
1 11 4
1 12 3
1 12 5
2 20 1
2 ...
Hello All!
I have a user model with attributes 'first' and 'last'
So for example
User.first.first #=> "Charlie"
User.first.last #=> "Brown"
This User model also has a virtual attribute 'full_name'
#user.rb
def full_name
[first,last].join(' ')
end
def full_name=(name) #don't know what to do with people w/ middle names
split = name...
I need to dump my sql query result into the text file. i have created the following query,
DECLARE @cmd VARCHAR(2048)
SET @cmd = 'OSQL -Slocalhost '
+ ' -UCRN370 -PCRN370'
+ ' -Q"SELECT TOP 5 GageId FROM EwQMS370..msgages"'
+ ' -oc:\authors.csv'
EXEC master..xp_cmdshell @cmd, NO_OUTPUT
The ab...
Hi,
How can we find the job dependency in SQL server.
Therotically basing on the success of first one job the other job begins.
Thanks a lot in advance!!
...
I am looking into creating something that does this:
SELECT *
FROM (`tm_accounts`)
WHERE CONCAT(`last_name`, `first_name`) LIKE '%o%'
This, of course, doesn't work. I just want you to see the idea behind what I'm trying to emulate.
last_name and first_name are two separate fields in the accounts table
...
Hi, I was trying to contact the author of a book I am reading on SQL Server query performance, but it seems the e-mail address provided in the book does not exis any more. So I decided to ask the community. I am pasting the messasge I had written below. Thanks in advance.
======
I have bought your book (SQL Server 2008 Query Performanc...
Hi,
I have a situation in oracle where I have two tables - Table A and Table B.
Table A has the following columns (aid, owner_id, app_id) and
Table B has the following columns (bid, aid, emp_no)
Table B has a foreign key (aid) back to Table A.
Based on the above tables, I am trying to write a query where an emp_...
There is a need to update one field to the same value in a heap of records. Using the DAO/ORM structure, I would retrieve each parent object, loop through each child object, update it's field, and then save it.
It would be faster to just write the SQL: update table set field = value where criteria = specified.
How do I fit these things...