sql

How do create table with dynamic no. of columns for data entry

Hi I'm currently working on a project where I need to save data depending upon the active no. of items. Its like.. Stores can have n no of items which can be dynamically added or reduced from admin back-end. Each item can either be activated or deactivated. NO problem. But I need to manage/save these dynamic n no. of items in a table...

SQL and toad

I have a select query that fetches some values based on user input, for EG :- SELECT company, accounts from testdrive WHERE company LIKE '&Company', accounts = '&Account' order by company desc On running this in Toad, the user is prompted for values.. but I want to know how can the USER specify the "conditions" ALONG with the va...

Column name or number of supplied values does not match table definition wthout droping table

In SQL server, I am trying to insert values from one table to another by using the below query : insert into tblTable1 ( [Week], 20001, 20002, 20003, 20004, 20006, 20005, W/c ) select * from tblTable1_link ( [Week], 20001, 20002, 20003, 20004, 20006, 20005, W/c ) I am getting the following error : Serv...

Besides a declarative language, is SQL a functional language?

Why yes or why not? ...

How can I import a database schema into MS Access 2003 from sql text file?

I chave a db schema generated in a text file (DDL - MS Access compliant). Where is the option in MS Acces to import that damn schema into na empry database ? ...

Replace SQL statements in XML with query results

Hey everyone, I have functions in place that will convert the results of sql queries into XML. However, I now want to be able to, using PHP, read in an XML document (that has nested SQL statements), execute those statements, and essentially replace the sql statement with the results. (Just a note, using PostgreSQL) For example: <cus...

SQL Server ALTER field NOT NULL takes forever

I want to alter a field from a table which has about 4 million records. I ensured that all of this fields values are NOT NULL and want to ALTER this field to NOT NULL ALTER TABLE dbo.MyTable ALTER COLUMN myColumn int NOT NULL ... seems to take forever to do this update. Any ways to speed it up or am I stuck just doing it overnight dur...

mysql limit inside group?

I want to limit the size of records inside a group, and here is my trial, how to do it right? mysql> select * from accounts limit 5 group by type; ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right...

SQL Server BETWEEN problem

I have a table mapping postal code ranges to contacts. Postal codes are saved in multiple formats for different countries. Table postcode-range: FROM-CODE TO-CODE CONTACT-ID COUNTRY-CODE 12000 12999 18 fr BT000000 BT9ZZZZZ 34 uk ... To find a contact in a specific range , e.g. range star...

sql join problem with negatives

I need to select data from two table using a join. This is fairly simple and have no problems here. The problem occurs when the field I am joining is used as two separate foreign keys (I didn't design this). So the ID field that I join on is either a positive or negative number. If it's a positive number it relates to ID_1 on the table_...

How do I calculate a running total in SQL without using a cursor?

I'm leaving out all the cursor setup and the SELECT from the temp table for brevity. Basically, this code computes a running balance for all transactions per transaction. WHILE @@fetch_status = 0 BEGIN set @balance = @balance+@amount insert into @tblArTran values ( --from artran table @artranid, @trandate, @typ...

Linq query with left join and group

I'm unable to convert this SQL query into a working linq statement select sum(cena), id_auta, max(servis) from dt_poruchy left outer join mt_auta on dt_poruchy.id_auta=mt_auta.id where dt_poruchy.servis>=3 group by id_auta; I tryed something like this but i cant handle the select statement var auta = from a in MtAuta.FindAll() ...

sql: why does query repeat values when using 'GROUP CONCAT' + 'GROUP BY'?

The Query: SELECT MemberId, a.MemberName, GROUP_CONCAT(FruitName) FROM a LEFT JOIN b ON a.MemberName = b.MemberName GROUP BY a.MemberName Table a MemberID MemberName -------------- ---------- 1 Al 1 Al 3 A2 Table b MemberName...

Sample SQL Data

I want to present a schema to my BA team. Select TABLE_NAME, col.DATA_TYPE from INFORMATION_SCHEMA.COLUMNS col order by col.TABLE_CATALOG, TABLE_NAME, TABLE_SCHEMA, col.ORDINAL_POSITION I want to present 3 rows of sample data as well but I wanted to pivot it out so they get an output that has the following 3 columns: Table_Name Dat...

Sql Query to Linq

How would I convert this query from SQL to Linq: SELECT status As 'Status', count(status) As 'Count' FROM tbl_repair_order WHERE contract = 'con' and (status = 'Parts Arr' or status = 'NA' or status = 'New Call' or status = 'Parts Ord' or status = 'Parts Req' or status = 'F Work') G...

SELECT non-duplicate records joined to table with duplicate date records, by last date

The title probably doesn't make much sense, so I'll try to be descriptive here in the subject. Consider 2 tables in MSSQL2005: Cases table: id int, caseNo string Events table: id int, caseID int, eventDate date/time I need a select statement for a view which will return single rows of: cases.caseNo, events.eventDate (date part on...

Oracle SQL Invalid Identifier

I'm trying to run this query but I get "ORA-00904: "Z1"."LONGITUDE": invalid identifier" Is there a way to rewrite this so I have access to that column in the exists subquery? Or is there generally a better way to achieve what I'm trying to do? Thanks select zip, count(UNIQUE address_id) LOCATIONS from records inner join addresses a...

MySQL joins to display categories, subcategories and subsubcategories

I have three tables: categories, subcategories and subsubcategories. I want to display a list that's formatted like: dvds cds cds > pop cds > blues cds > new age cds > new age > whale noises books books > cowboys books > zombies I've managed to display everything except for the names of categories on their own when they have children,...

Finding the higest voted Question in last week. (sql query)

Hello I have a 3 sql tables: qotwQuestion1a(QuestionId [primarykey], Question, MemberId, PostDate); qotwVote1a (QuestionId [primarykey], MemberId [primarykey], Vote1a); qotwMember (MemberId [primarykey], Name, Password, emailId); I want to write a sql query to find the QuetionId and MemberId of the Question that has the highest vote...

Update Field in Join table

Hi Experts, I have a select query as SELECT MFD.MONTHLY_FUND_HEADER_ID FROM MONTHLY_FUND_DETAIL MFD, MONTHLY_FUND_HEADER MFH WHERE MFH.MONTH < TO_CHAR(TRUNC(sysdate), 'MM') AND MFH.YEAR <= TO_CHAR(TRUNC(sysdate), 'YYYY') AND MFH.CERTIFIED_DT IS NOT NULL AND MFD.SENT_TO_EXT_IND = 'N' AND MFH.COURT_CD = '56' GROUP BY MFD....