Hi !
I have a table with many rows, is there any way to find out when a concrete row has been inserted? (I don't have create/update time columns)
Thanks
I have a hierarchical data structure which I'm displaying in a webpage as a treeview.
I want to data to be ordered to first show nodes ordered alphabetically which have no children, then under these nodes ordered alphabetically which have children. Currently I'm ordering all nodes in one group, which means nodes with children appear next to nodes with no children.
I'm using a recursive method to build up the treeview, which has this LINQ code at it's heart:
var filteredCategory = from c in category
orderby c.Name ascending
where c.ParentCategoryId == parentCategoryId && c.Active == true
select c;
So this is the orderby statement I want to enhance.
Shown below is the database table structure:
[dbo].[Category](
[CategoryId] [int] IDENTITY(1,1) NOT NULL,
[Name] [varchar](100) NOT NULL,
[Level] [tinyint] NOT NULL,
[ParentCategoryId] [int] NOT NULL,
[Selectable] [bit] NOT NULL CONSTRAINT [DF_Category_Selectable] DEFAULT ((1)),
[Active] [bit] NOT NULL CONSTRAINT [DF_Category_Active] DEFAULT ((1))
I've tried using curl to add new events to yahoo, succeeded in logging in and getting the calendar add events page, but when i try to post events using curl, it redirects me to login page. Please suggest what can i do...?
Thanks in advance
I've got a table that has two fields (custno and custno2) that need to be searched from a query. I didn't design this table, so don't scream at me. :-)
I need to find all records where either the custno or custno2 matches the value returned from a query on the same table based on a titleno.
In other words, the user types in 1234 for the titleno. My query searches the table to find the custno associated with the titleno. It also looks for the custno2 for that titleno. Then it needs to do a search on the same table for all other records that have either the custno or custno2 returned in the previous search in the custno or custno2 fields for those other records.
Here is what I've come up with:
SELECT BILLYR, BILLNO, TITLENO, VINID, TAXPAID, DUEDATE, DATEPIF, PROPDESC
FROM TRCDBA.BILLSPAID
WHERE CUSTNO IN
(select custno from trcdba.billspaid where titleno = '1234'
union select custno2 from trcdba.billspaid where titleno = '1234' and custno2 != '')
OR CUSTNO2 IN
(select custno from trcdba.billspaid where titleno = '1234'
union select custno2 from trcdba.billspaid where titleno = '1234' and custno2 != '')
The query takes about 5-10 seconds to return data. Can it be rewritten to work faster?
I am trying to find all deals information along with how many comments they have received. My query
select deals.*,
count(comments.comments_id) as counts
from deals left join comments on
comments.deal_id=deals.deal_id where
cancelled='N'
But now it only shows the deals that have at least one comment. What is the problem?
My site has a messaging feature where one user may message another. The messages support threading - a parent message may have any number of children but only one level deep.
The messages table looks like this:
Messages
- Id (PK, Auto-increment int)
- UserId (FK, Users.Id)
- FromUserId (FK, Users.Id)
- ParentMessageId (FK to Messages.Id)
- MessageText (varchar 200)
I'd like to show messages on a page with each 'parent' message followed by a collapsed view of the children messages.
Can I use the GROUP BY clause or similar construct to retrieve parent messages and children messages all in one query? Right now I am retrieving parent messages only, then looping through them and performing another query for each to get all related children messages.
I'd like to get messages like this:
Parent1
Child1
Child2
Child3
Parent2
Child1
Parent3
Child1
Child2
I have two tables
Publishers and Campaigns, both have similar many-to-many relationships with Countries,Regions,Languages and Categories.
more info
Publisher2Categories has publisherID and categoryID which are foreign keys to publisherID in Publishers and categoryID in Categories which are identity columns. On other side i have Campaigns2Categories with campaignID and categoryID columns which are foreign keys to campaignID in Campaigns and categoryID in Categories which again are identities.
Same goes for Regions, Languages and Countries relationships
I pass to query certain publisherID and want to get campaignIDs of Campaigns that have at least one equal to Publisher value from regions, countries, language or categories
thanks
I have the following columns in TableA
TableA
Column1 varchar
Column2 int
Column3 bit
I am using this statement
IF Column3 = 0
SELECT Column1, Column2 FROM
TableA WHERE
Column2 > 200
ELSE
SELECT Column1, Column2 FROM
TableA WHERE
Column2 < 200
But the statment does not compile. It says Invalid Column Name 'Column3'
Select
id,
sum(amount),
vat
From transactions WHERE id=1;
Each record in this table has a vat percentage, I need to get the total amount in all records, however each amount has to be multiplied by by its vat %.
Is there away to do this without looping through all records?
I am not able to find an answer to this. Does anybody know this? I want to enable the download of .bak file and for that I need to know the mime type so that i configure the same in the IIS for .bak file.
Any help is appreciated.
Hi,
I am trying to Join 2 seperate columns from 2 different sheets to make a longer column from which i can then use a Vlookup from.
Sheet1
A, B, C, D, E, F, G
Sheet2
A, B, C, D, E, F, G
I want to Join(Union) Columns B from sheet1 and C from sheet2 together and find the Distinct values of the new list. I have been working on this for weeks.
Thanks
I curious to know how people are using table alias. The other developers where I work always use table alias, and always use the alias of a, b, c, ect.
Here's an example
SELECT a.TripNum, b.SegmentNum, b.StopNum, b.ArrivalTime
FROM Trip a, Segment b
WHERE a.TripNum = b.TripNum
I disagree with them, and think table alias should be use more sparingly. I think it should be used when including the same table twice in a query, or when the table name is very long and using a shorter name in the query will make the query easier to read. I also think the alias should be a good name instead of a letter. In the above example if I felt I needed to use 1 letter table alias I would use t for the Trip table and s for the segment table.
I have sql backups copied from server A to server B on a nightly basis.
We want to move the sql server from server A to server B without much downtime, but the files are very large.
I assumed that performing a differential backup and restore would solve the problem with the databases.
Copy full backup from server A to copy to server B (10+gb)
Open SQL Server Managment Studio on server B
Right mouse on databases
Restore Database
Type in the new DB-name
Choose "From Device" and browse to the backup file
Click Okay. This is now resorting the original "full" backup.
Test new db with dev application - everything works :)
On original database rightmouse on DB Tasks Backup...
Backup Type = Differential, Backup to disk, add a new file, and remove the old one (it needs to be a small file to transfer for the smallest amount of outage)
Copy the diff backup onto the new db
Right mouse on DB Tasks Restore Database
This is where I get stuck. If I add both the new differential file, and the original backup to the restore process I get an error
The media loaded on "M:\path\to\backup\full.bak" is formatted to support 1 media families, but 2 media families are expected according to the backup device specification.
RESTORE HEADERONLY is terminating abnormally.
But if I try to restore using just the differential file I get
System.Data.SqlClient.SqlError: The log or differential backup cannot be restored because no files are ready to rollforward. (Microsoft.SqlServer.Smo)
Any idea how to do it? Is there a better way of restoring backups with limited downtime?
Hi,
Not able to execute a query ,i need to check if end date is greater than today in the following query
Getting an error invalid query
select * from table1 where user in ('a') and END_DATE >'2010-05-22'
getting an error liter string does not match
when i run this code, it returns the topic fine...
$query = mysql_query("SELECT topic
FROM question
WHERE id = '$id'");
if(mysql_num_rows($query) > 0) {
$row = mysql_fetch_array($query) or die(mysql_error());
$topic = $row['topic'];
}
but when I change it to this, it doesn't run at all. why is this happening?
$query = mysql_query("SELECT topic, lock
FROM question
WHERE id = '$id'");
if(mysql_num_rows($query) > 0) {
$row = mysql_fetch_array($query) or die(mysql_error());
$topic = $row['topic'];
$lockedThread = $row['lock'];
echo "here: " . $lockedThread;
}
let's say I have this query:
select * from table1 r where r.x = 5
do the speed of this query depends on the number of rows that are present in table1 ?
Hi all,
I have a table in MsSQL Server 2008 (SP2) containing 30 millios of rows, table size 150GB, there are a couple of int columns and two nvarchar(max) columns: one containing text (from 1-30000 characters) and one containg xml (up to 100000 characters).
Table doesn't have any primary keys or indexes (its is a staging table). So atm I am running a query:
UPDATE [dbo].[stage_table]
SET [column2] = SUBSTRING([column1], 1, CHARINDEX('.', [column1])-1);
the query is running for 3 hours (and it is still not completed), which I think is too long. Is It? I can see that there is constant read rate of 5MB/s and write rate of 10MB/s to .mdf file.
How can I find out why the query is running so long? The "server" is i7, 24GB of ram, SATA disks on RAID 10.
Many thanks!
I'm attempting to map an entity hierarchy using NHibernate almost all of which have events. When attempting to build a session factory however, I get error messages similar to the following:
Core.Domain.Entities.Delivery: method
remove_Scheduled should be virtual
Delivery is an entity in my domain model with an event called Scheduled. Since events cannot be declared virtual I'm at a loss as to how to proceed here. Why would NHibernate need events to be virtual?
I want to calculate the Sum of the Field which has Time DataType.
My Table is Below:
TableA:
TotalTime
-------------
12:18:00
12:18:00
Here I want to sum the two time fields.
I tried the below Query
SELECT CAST(
DATEADD(MS, SUM(DATEDIFF(MS, '00:00:00.000',
CONVERT(TIME, TotalTime))), '00:00:00.000'
) AS TOTALTIME)
FROM [TableA]
But it gives the Output as
TOTALTIME
-----------------
00:36:00.0000000
But My Desired Output would be like below:
TOTALTIME
-----------------
24:36:00
How to get this Output?
I have two tables. One has rows with values A-Z and the other has D-G.
How do I make a select statement to return only the values A-C, H-Z?
(This is, of course a dumbed down version of my real tables and problem.)
G'day
I think I have a misunderstanding of serializable. I have two tables (data, transaction) which I insert information into in a serializable transaction (either they are both in, or both out, but not in limbo).
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRANSACTION
INSERT INTO dbo.data (ID, data) VALUES (@Id, data)
INSERT INTO dbo.transactions(ID, info) VALUES (@ID, @info)
COMMIT TRANSACTION
I have a reconcile query which checks the data table for entries where there is no transaction at read committed isolation level.
INSERT INTO reconciles (ReconcileID, DataID)
SELECT Reconcile = @ReconcileID, ID FROM Data
WHERE NOT EXISTS (SELECT 1 FROM TRANSACTIONS WHERE data.id = transactions.id)
Note that the ID is actually a composite (2 column) key, so I can't use a NOT IN operator
My understanding was that the second query would exclude any values written into data without their transaction as this insert was happening at serializable and the read was occurring at read committed. I have evidence that reconcile is picking up entries
A colleague is adding a bit mask to all our database tables. In theory this is so we can track certain properties of each row across the entire system. For example...
Is the row shipped with the system or added by the client once they've started using the system
Has the row been deleted from the table (soft deletes)
Is the row a default value within a set of rows
Is this a good idea? Are there other uses where this approach would be beneficial?
My preference is these properties are obviously important, and having a dedicated column for each property is justified to make what is happening clearer to fellow developers.
First, I am SO sorry if the answer is out there. I've looked and looked and feel this is such a simple thing that it should be obvious.
I'm wanting to make sure only the person who added an event can modify it. Simple!
I already have a datasource that has event_added_by as a data point. It is populating a FormView.
SelectCommand="SELECT * FROM [tbl_events] WHERE ([event_ID] = @event_ID)"
And I have Page.User.Identity.Name.
How do I compare the two? I can't pull the value from the label in the FormView so I need to find another way.
if (!IsPostBack)
{
string uname = Page.User.Identity.Name;
string owner = ""// this is where I need to grab the value from dsEvents;
if (uname != owner)
{
//Send them somewhere saying they're not allowed to be here
}
}
TIA for any help!