Hello,
I've 3 columns that I'd like to sort in the Excel way, i.e. sorting the first column, and for each element sorted in the first column, I'll sort the second column, and so on. Let's say I first sort alphabeticaly Countries, then for each country, I sort alphabeticaly cities. How do I do it using Linq2Sql?
Thanks for helping
Hi.
If i have the following method -
public static void C() {
Connection con = DriverManager.getConnection();
.... // code
return;
}
and i dont call con.close() , will the connection terminate automatically once the method returns?
I have many columns in oracle database and some new are added with values. I like to find out which columns have values other than 0 or null. So I am looking for column names for which some sort of useful values exists at least in one row.
How do I do this?
Update: This sounds very close. How do I modify this to suit my needs?
select column_name, nullable, num_distinct, num_nulls
from all_tab_columns
where table_name = 'SOME_TABLE'
I've got a little time-tracking web app (implemented in Rails 3.2.8 & MySQL). The app has several users who add their time to specific tasks, on a given date. The system is set up so a user can only have 1 time entry (i.e. row) per task per date. I.e. if you add time twice on the same task and date, it'll add time to the existing row, rather than create a new one.
Now I'm looking to merge 2 tasks. In the simplest terms, merging task ID 2 into task ID 1 would take this
time | user_id | task_id | date
------+----------+----------+-----------
10 | 1 | 1 | 2012-10-29
15 | 2 | 1 | 2012-10-29
10 | 1 | 2 | 2012-10-29
5 | 3 | 2 | 2012-10-29
and change it into this
time | user_id | task_id | date
------+----------+----------+-----------
20 | 1 | 1 | 2012-10-29 <-- time values merged (summed)
15 | 2 | 1 | 2012-10-29 <-- no change
5 | 3 | 1 | 2012-10-29 <-- task_id changed (no merging necessary)
I.e. merge by summing the time values, where the given user_id/date/task combo would conflict.
I figure I can use a unique constraint to do a ON DUPLICATE KEY UPDATE ... if I do an insert for every task_id=2 entry. But that seems pretty inelegant.
I've also tried to figure a way to first update all the rows in task 1 with the summed-up times, but I can't quite figure that one out.
Any ideas?
I have a table T1 such that
gsdv |nsdv |esdv
-------------------
228.90 |216.41|0.00
and a table T2 such that
ds |nm
--------------------------
'Non-Revenue Sales'|'ESDV'
'Gross Sales' |'GSDV'
'Net Sales' |'NSDV'
How do I get the following table?
ds |nm |val
---------------------------------
'Non-Revenue Sales'|'ESDV'|0.00
'Gross Sales' |'GSDV'|228.90
'Net Sales' |'NSDV'|216.41
I know that I can this by doing the following
SELECT ds,nm,esdv val FROM T1,T2 WHERE nm = 'esdv'
UNION
SELECT ds,nm,gsdv val FROM T1,T2 WHERE nm = 'gsdv'
UNION
SELECT ds,nm,nsdv val FROM T1,T2 WHERE nm = 'nsdv'
but I am looking for a more generic/nicer solution. I am using Sybase, but if you can think of a way to do this with other DBMS, please let me know.
Thanks.
Hi,
i have two tables
Order(id, date, note)
and
Delivery(Id, Note, Date)
I want to create a trigger that updates the date in Delivery when the date is updated in Order.
I was thinking to do something like
CREATE OR REPLACE TRIGGER your_trigger_name
BEFORE UPDATE
ON Order
DECLARE
BEGIN
UPDATE Delivery set date = ??? where id = ???
END;
How do I get the date and row id?
thanks
I'm looking at building a facility which allows querying for data with hierarchical filtering. I have a few ideas how I'm going to go about it but was wondering if there are any recommendations or suggestions that might be more efficient.
As an example imagine that a user is searching for a job. The job areas would be as follows.
1: Scotland
2: --- West Central
3: ------ Glasgow
4: ------ Etc
5: --- North East
6: ------ Ayrshire
7: ------ Etc
A user can search specific (ie Glasgow) or in a larger area (ie Scotland).
The two approaches I am considering are
1: keep a note of children in the database for each record (ie cat 1 would have 2, 3, 4 in its children field) and query against that record with a SELECT * FROM Jobs WHERE Category IN Areas.childrenField.
2: Use a recursive function to find all results who have a relation to the selected area
The problems I see from both are
1: holding this data in the db will mean having to keep track of all changes to structure
2: Recursion is slow and inefficent
Any ideas, suggestion or recommendations on the best approach? I'm using C# ASP.NET with MSSQL 2005 DB.
I have this PHP page where the user can select and un-select items. The interface looks like this:
Now I'm using these code, when the user hit the save changes button:
foreach( $value as $al_id ){ //al_id is actually location id
//check if a record exists
//if location were assigned and leave it as is
$assigned_count = $this->AssignedLoc->checkIfAssigned( $tab_user_id, $al_id );
if( $assigned_count == 0 ){
//else if not, insert this new record
$this->insertAssigned( $tab_user_id, $company_id, $al_id );
}
}
Now my question is, how do I delete the un assigned locations? For example in the screenshot above, there are 4 assigned locations, if I'm gonna remove (or unassign) "Mercury Morong" and "GP Hagonoy" from the assigned locations, only two must remain. What are the possible solutions using PHP?
Thanks for any help!
I've a typical scenario & need to understand best possible way to handle this, so here it goes -
I'm developing a solution that will retrieve data from a remote SOAP based web service & will then push this data to an Oracle database on network.
Also, this will be a scheduled task that will execute every 15 minutes.
I've event queues on remote service that contains the INSERT/UPDATE/DELETE operations that have been done since last retrieval, & once I retrieve the events for last 15 minutes, it again add events for next retrieval.
Now, its just pushing data to Oracle so all my interactions are INSERT & UPDATE statements.
There are around 60 tables on Oracle with some of them having 100+ columns. Moreover, for every 15 minutes cycle there would be around 60-70 Inserts, 100+ Updates & 10-20 Deletes.
This will be an executable jar file that will terminate after operation & will again start on next 15 minutes cycle.
So, I need to understand how should I handle WRITE operations (best practices) to improve performance for this application as whole ?
Current Test Code (on every cycle) -
Connects to remote service to get events.
Creates a connection with DB (single connection object).
Identifies the type of operation (INSERT/UPDATE/DELETE) & table on which it is done.
After above, calls the respective method based on type of operation & table.
Uses Preparedstatement with positional parameters, & retrieves each column value from remote service & assigns that to statement parameters.
Commits the statement & returns to get event class to process next event.
Above is repeated till all the retrieved events are processed after which program closes & then starts on next cycle & everything repeats again.
Thanks for help !
I have 4 tables: tempTBL, linksTBL and categoryTBL, extra
on my tempTBL I have: ID, name, url, cat, isinserted columns
on my linksTBL I have: ID, name, alias columns
on my categoryTBL I have: cl_id, link_id,cat_id
on my extraTBL I have: id, link_id, value
How do I do a single query to select from tempTBL all items where isinsrted = 0 then insert them to linksTBL and for each record inserted, pickup ID (which is primary) and then insert that ID to categoryTBL with cat_id = 88. after that insert extraTBL ID for link_id and url for value.
I know this is so confusing, put I'll post this anyhow...
This is what I have so far:
INSERT IGNORE INTO linksTBL (link_id,link_name,alias)
VALUES(NULL,'tex2','hello'); # generate ID by inserting NULL
INSERT INTO categoryTBL (link_id,cat_id)
VALUES(LAST_INSERT_ID(),'88'); # use ID in second table
I would like to add here somewhere that it only selects items where isinserted = 0 and iserts those records, and onse inserted, will change isinserted to 1, so when next time it runs, it will not add them again.
Hi ,
I have created Dealer dimension in SSAS 2005 and it has 3 hierarchies. By default the hierarchy created first is the default hierarchy of the dimension.
Is there any way to change the default hierarchy to another hierarchy.
Hi
In my mode I am selecting a field as
$query1 = $this->db->query("SELECT dPassword
FROM tbl_login
WHERE dEmailID='[email protected]'");
How to return dpassword as a variable to my controller
I tried this way return dpassword;
for eg...
SELECT * FROM
( SELECT RANK() OVER (ORDER BY stud_mark DESC) AS ranking, stud_id, stud_name, stud_mark FROM tbl_student )
AS foo WHERE ranking = 10
Here foo is present...actually what it does ?..
I have created a dataset with fields "LastRunBuild" and "project" .The LastRunBuild field contain string of data seperated by commas according to each project. But Some Projects have no value in LastRunBuild field.When i am using this expression
" iif(Fields!LastRunBuild.Value=nothing,
nothing,Split(Fields!LastRunBuild.Value,",").GetValue(3)) "
a #Error value returns every time. Please reply...
I have 2 tables:
Table A: code | name
Table B: barcode | name
Table B has full barcode and name, Table A has only code.
I need to run update query that fill name in Table A.
I tried something like:
update A set name = (select top 1 Name from B where B.Code = mid(A.Barcode,1,8))
but it doesn't work.
Hello,
I'm developing a database to store statistics for a sports league.
I'd like to show several tables:
- league table that indicates the position of the team in the current and previous fixture
- table that shows the position of a team in every fixture in the championship
I have a matches table:
Matches (IdMatch, IdTeam1, IdTeam2, GoalsTeam1, GoalsTeam2)
Whith this table I can calculate the total points of every team based on the matches the team played. But every time I want to show the league table I have to calculate the points.
Also I have a problem to calculate in which position classified a team in the last 10 fixtures cause I have to make 10 queries.
To store the league table for every fixture in a database table is another approach, but every time I change a match already played I have to recalculate every fixture from there...
Is there a better approach for this problem?
Thanks
Is there some way to remove data about all users , roles e t c from some Web application into aspnet database tables ?
tables like dbo.aspnet_Applications (here is this application that I want to remove)
but also I need to remove all data with this application in other tables...
I dont understand what is wrong with this query it is giving me compile time error of command not ended properly.The inner query is giving me 4 records can any body help me out.
select WGN3EVENTPARTICIPANT.EVENTUID
from
(Select WGN_V_ADDRESS_1.ADDRESSUID1 as add1,
WGN_V_ADDRESS_1.ADDRESSUID2 as add2
from WGN3USER inner join
WGN_V_ADDRESS_1 on WGN_V_ADDRESS_1.USERID=wgn3user.USERID
where WGN3USER.USERNAME='FIRMWIDE\khuraj'
) as ta
,WGN3EVENTPARTICIPANT
where (ta.ADDRESSUID1=WGN3EVENTPARTICIPANT.ADDRESSUID1) AND
(ta.ADDRESSUID2=WGN3EVENTPARTICIPANT.ADDRESSUID2)
I am running it in oracle.
Thanks
Amandeep
I have a large number of rows that I would like to copy, but I need to change one field.
I can select the rows that I want to copy:
select * from Table where Event_ID = "120"
Now I want to copy all those rows and create new rows while setting the Event_ID to 155. How can I accomplish this?
I have a column that contains links. The problem is that the titles of the links are in the same column, so it looks like this:
linktitle|-|linkurl
I want link title and linkurl in separate columns.
I've created a new column for the urls, so I'm looking for a way to extract them and update the linkurl column with them. Is there any clever way to construct a query that does this?
Ok here's the deal I got one table with a bunch of client information.
Each client makes up to one purchase a year which is represented by an individual row.
there's a column for the year and there's a column the contains a unique identifier for each client. What I need to do is to construct a query that takes last year and this year and shows me which clients were here made a purchase last year but not make a purchase this year.
I also need to build a query that shows me which clients did not make a purchase last year and the year before last but did make a purchase this year.
I want to make a festival calendar using asp.net from that I used two ajax calendar and one textbox it is a festival textbox where we enter festival which FromDate and ToDate respectively. I want to do this as following point
If I enter in textbox Christmas and Choose Fromdate=25/12/2011 and ToDate=31/12/2011 then it will be valid
If I choose fromDate=25/12/2011 and ToDate=24/12/2011 then it will invalid
If I choose Fromdate=25/12/2011 and Todate=28/12/2011 then also it is invalid because it coming in between 25/12/2011 and 31/12/2011
If I Choose fromdate=1/1/2011 and ToDate=1/1/2011 then it is valid
If I choose fromdate=21/12/2011 and 25/12/2011 then it is invalid because of already Christmas done in 1/1/2011
And all date should show in gridview like 25-dec-2011 format
Here is my code:
DateTime dt1 = Convert.ToDateTime(txt_fromdate.Text);
DateTime dt2 = Convert.ToDateTime(txt_todate.Text);
if (dt1 > dt2)
{
con.Open();
com = new SqlCommand("BTNN_MovieDB_Festival_Details_Insert", con);
com.Parameters.Add("@fromdate", SqlDbType.VarChar).Value = dateformat_mmdd(txt_fromdate.Text.ToString().Trim());
com.Parameters.Add("@todate", SqlDbType.VarChar).Value = dateformat_mmdd(txt_todate.Text.ToString().Trim());
com.Parameters.Add("@return", SqlDbType.VarChar).Direction = ParameterDirection.ReturnValue;
com.ExecuteNonQuery();
con.Close();
showdata();
}
else if (dt1 < dt2)
{
lblerror.Text = "ToDate should be greater than FromDate";
}
how do i write a query that returns aggregate sales data for California in the past x months.
----------------------- -----------------------
| order | | customer |
|-----------------------| |-----------------------|
| orderId int | | customerId int |
| customerId int | | state varchar |
| deposit decimal | -----------------------
| orderDate date |
-----------------------
-----------------------
| orderItem |
|-----------------------|
| orderId int |
| itemId int |
| qty int |
| lineTotal decimal |
| itemPrice decimal |
-----------------------