I saw some topics about this, but the problem is that the solutions required a "switch case"... Like this
I have a table with a lot of columns, is there a way to do a dynamic sort without the switch?
I have a report that we need to link (which we've checked to be working) to in a JSF project, the link looks like the following:
http://www.example.com/report/summary&rs:Command=Render
However when we try to load the page that links to it we get the following error:
The reference to entity "rs:Command" must end with the ';'
How can I link to the report within my pages and prevent it from trying to parse the rs:Command?
Here's the query i'm trying to convert into Linq:
SELECT R.Code,
R.FlightNumber,
S.[Date],
S.Station,
R.Liters,
SUM(R.Liters) OVER (PARTITION BY Year([Date]), Month([Date]), Day([Date])) AS Total_Liters
FROM S INNER JOIN
R ON S.ID = R.SID
WHERE (R.Code = 'AC')
AND FlightNumber = '124'
GROUP BY Station, Code, FlightNumber, [Date], Liter
ORDER BY R.FlightNumber, [Date]
Thanks for any help.
I've got a site where users follow users they like and can read their latest updates.
I'd like to show my users a simple count of how many comments the people they follow have posted in the last 24 hours. I'm having trouble figuring out the query.
I have two tables.
comment
-cid (comment id)
-timestamp
-uid (id of person who posted the comment)
-comment (content of the comment)
user_relationships
-requester_id (id of the user who followed the person)
-requestee_id (id of the person who was followed)
In plain english, I think the query is something like this:
COUNT the cid.comment from the comments table where uid.comment is equal to requestee_id.user_relationships associated with requester_id.user_relationships value of X.
I need to get all the UIDs of people being followed by a given UID from the user_relationship table. Then count up how many comments those people have posted in the last 24 hours and spit that number out.
What would this query look like?
I am trying to take database backup. How can I do that when getdate is being appended with file name with format dd/mm/yyyy.
declare @dbName VARCHAR(100)
declare @path VARCHAR(100)
set @dbName='CallMeIndia'
set @path='F:\'+@dbName +'-'+convert(varchar(50),getdate(),103)+'.bak'
BACKUP DATABASE @dbName
TO DISK= @path
I need to find the path of the database (MDF) or at least the database logs loaded but for some reasons I cannot login through the MSSQL server so I need to know if you know any file/config file that keeps the path of the databases or log file .
I have a stored procedure called from a C# code-behind. The code fires but the update command does not get performed. The stored procedure, if run directly, works. I think I am having a brain fart. Please help. :)
CODEBEHIND
protected void btnAbout_Click(object sender, EventArgs e)
{
SqlConnection myConnection = new SqlConnection(strConnection);
SqlCommand myCommand = new SqlCommand("spUpdateCMSAbout", myConnection);
myConnection.Open();
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.Parameters.Add("@AboutText", SqlDbType.NVarChar, -1).Value = txtAbout.Text.ToString();
myCommand.ExecuteNonQuery();
myConnection.Close();
}
STORED PROCEDURE
ALTER PROCEDURE fstage.spUpdateCMSAbout
(
@AboutText nvarchar(max)
)
AS
BEGIN
SET NOCOUNT ON;
UPDATE fstage.staticCMS SET About = @AboutText;
END
HTML
<asp:Button ID="btnAbout" runat="server"
Text="Save" CausesValidation="False" onclick="btnAbout_Click"
UseSubmitBehavior="False" />
C# .NET 4.0
I need to write a query that creates a view that calculates the total cost of each sale, by considering quantity and price of each bought item. The view should return the debit and total cost.
In the answer each debit-number should only occur once.
Thanks in advance
Table ITEM:
ID NAME PRICE
118 Jeans 100
120 Towel 20
127 Shirt 55
Table DEBIT:
DEBIT ITEM Quantity
100581 118 5
100581 120 1
100586 127 5
For example, i always generate an auto-increment field for the users table, but i also specifies an UNIQUE index on their usernames.
There is situations that i first need to get the userId for a given username and then execute the desired query. Or use a JOIN in the desired query.
It's 2 trips to the database or a JOIN vs. a varchar index
The above is just an example
There is a real performance benefit on INT over small VARCHAR indexes?
Thanks in advance!
I was looking for a way to create a trigger that would insert the same row into two tables with the same values.
For example, a new row is inserted into pushNotificationQueue as soon as that is inserted, I would like that same exact row to be inserted into messages.
I tried this
CREATE TRIGGER add_to_messages
after insert on mbb_pushNotificationQueue
FOR EACH ROW
insert into mbb_messages select * from mbb_pushNotificationQueue
the only problem with that is that it goes through and adds entries that have already been previously added.
Whenever I enable TCP/IP connections on my SQL Server Express 2008 database server running on Windows XP SP3, I cannot restart the service, it simply states "The request failed or did respond in a timely fashion". Any suggestions of what I may have configured incorrectly?
[update]
Here is the applicable part of the Error Log:
MSSQL$SQLEXPRESS Server failed to list on 'any' 3060. Error: 0x2747. To proceed, notify you system administrator.
MSSQL$SQLEXPRESS TDSSNIClient initialization failed with error 0x2747, status code 0xa. Reason: Unable to initialize the TCP/IP listener. An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.
MSSQL$SQLEXPRESS TDSSNIClient initialization failed with error 0x2747, status code 0x1. Reason: Initialization failed with an infrastructure error. Check for previous errors.
An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full.
MSSQL$SQLEXPRESS Could not start the network library because of an internal error in the network library. To determine the cause, review the errors immediately preceding this one in the error log.
MSSQL$SQLEXPRESS SQL Server could not spawn FRunCM thread. Check the SQL Server error log and the Windows event logs for information about possible related problems.
Hi
I have this kind of request :
SELECT myTable.ID,
myTable.Adress,
-- 20 more columns of all kind of type
FROM myTable
WHERE EXISTS(SELECT * FROM myLink
WHERE myLink.FID = myTable.ID
and myLink.FID2 = 666)
myLink has a lot of rows.
Do you think it's faster to do like this :
SELECT myLink.FID INTO @result
FROM myLink
WHERE myLink.FID2 = 666
UPDATE @result SET Adress = myTable.Adress,
-- 20 more columns of all kind of type
FROM myTable
WHERE myTable.ID = @result.ID
How many types of parameters are there in a stored procedures and what are they?
Thanks in advance.
And can we delete a table using view? I think yes but in what situation we can't delete it if there are no trigger associated with that table. I mean to say i need to delete a table which has no trigger associated with it using view, in which case i can't delete it?
I'm installing sqlserver 2008 express and I have a couple of questions,
by default on the collation, it has SQL_Latin1_General_CP1_CI_AS I'm just wondering which collation I should choose so that it can store all languages, English, Asian etc.
also this is a brand new installation on a brand new box, should I use Default Instance or a Named Instance.
Thank you,
Ray.
I'm working on a personal project (Search engine) and have a bit of a dilemma.
At the moment it is optimized for writing data to the search index and significantly slow for search queries.
The DTA (Database Engine Tuning Adviser) recommends adding a couple of Indexed views inorder to speed up search queries. But this is to the detriment of writing new data to the DB.
It seems I can't have one without the other!
This is obviously not a new problem.
What is a good strategy for this issue?
I cannot figure this out.
I need a solution to call a random function for it's percent.
Ex. there is 10% chances that the script calls subscriptions() and 3% chance that the system call the function "specialitems()".
I am stuck in this, so i hope someone can help me with this brainkiller.
<?php
class RandomGifts {
public $chances = '';
public function __construct($user) {
$this->user = $user;
//Find percent for each function
$this->chances = array(
'subscriptions' => 10, // 10%
'specialitems' => 3, // 5%
'normalitems' => 30, // 40%
'fuser' => 50, // 70%
'giftcards' => 7, // 7%
);
//This should call the function which has been calculated.
self::callFunction(?);
}
public function subscriptions(){}
public function specialitems(){}
public function normalitems(){}
public function fuser(){}
public function giftcards(){}
}
?>
The Product table has 700K records in it. The query:
SELECT TOP 1 ID,
Name
FROM Product
WHERE contains(Name, '"White Dress"')
ORDER BY DateMadeNew desc
takes about 1 minute to run. There is an non-clustered index on DateMadeNew and FreeText index on Name.
If I remove TOP 1 or Order By - it takes less then 1 second to run.
Here is the link to execution plan.
http://screencast.com/t/ZDczMzg5N
Looks like FullTextMatch has over 400K executions. Why is this happening? How can it be made faster?
I create a query: Select * from HR_Tsalary where month='3' and year ='2010' the result is 473 records and I found 2 duplicate record, then I create another query to find duplicate record only: SELECT Emp_No, COUNT(*) FROM HR_Tsalary WHERE year = '10' AND month = '3'GROUP BY Emp_No HAVING COUNT(*) 1 the result is zero record from client side (thru Visual Basic Adodb code). But when I use same query from server the result is 2 records. Is there any different when create a query between from server side and client side?
Tried my usual references at w3schools and google. No luck
I'm trying to produce the following results. QTY is a derived column
| Position | QTY
--------------------
1 Clerk 2
2 Mgr 2
Here's what I'm not having luck with:
SELECT Position, Count(position) AS 'QTY'
FROM tblemployee
Where ('QTY' != 1)
GROUP BY Position
I know that my Position is set up as varchar(255)
Count produces a integer data and my where clasue is accurate so that leads me to believe that that Count() is jamming me up. Please throw up an example so I can reference later. Thanks for the help!
I'd like to have a query returning two ResultSets each of which holding exactly half of all records matching a certain criteria. I tried using TOP 50 PERCENT in conjunction with an Order By but if the number of records in the table is odd, one record will show up in both resultsets. Example:
I've got a simple table with TheID (PK) and TheValue fields (varchar(10)) and 5 records. Skip the where clause for now.
SELECT TOP 50 PERCENT * FROM TheTable ORDER BY TheID asc
results in the selected id's 1,2,3
SELECT TOP 50 PERCENT * FROM TheTable ORDER BY TheID desc
results in the selected id's 3,4,5
3 is a dup. In real life of course the queries are fairly complicated with a ton of where clauses and subqueries.
Hi,
as topic says, I don't want to return the first two letters in the return values
just an example:
select companyname from companies
returns companyX
Can I write a query that returns panyX instead?
Thanks in advance
I have a simple query that relies on two full-text indexed tables, but it runs extremely slow when I have the CONTAINS combined with any additional OR search. As seen in the execution plan, the two full text searches crush the performance. If I query with just 1 of the CONTAINS, or neither, the query is sub-second, but the moment you add OR into the mix the query becomes ill-fated.
The two tables are nothing special, they're not overly wide (42 cols in one, 21 in the other; maybe 10 cols are FT indexed in each) or even contain very many records (36k recs in the biggest of the two).
I was able to solve the performance by splitting the two CONTAINS searches into their own SELECT queries and then UNION the three together. Is this UNION workaround my only hope?
Thanks.
SELECT a.CollectionID
FROM collections a
INNER JOIN determinations b ON a.CollectionID = b.CollectionID
WHERE a.CollrTeam_Text LIKE '%fa%'
OR CONTAINS(a.*, '"*fa*"')
OR CONTAINS(b.*, '"*fa*"')
Execution Plan (guess I need more reputation before I can post the image):
I've just learned ( yesterday ) to use "exists" instead of "in".
BAD
select * from table where nameid in (
select nameid from othertable where otherdesc = 'SomeDesc' )
GOOD
select * from table t where exists (
select nameid from othertable o where t.nameid = o.nameid and otherdesc = 'SomeDesc' )
And I have some questions about this:
1) The explanation as I understood was: "The reason why this is better is because only the matching values will be returned instead of building a massive list of possible results". Does that mean that while the first subquery might return 900 results the second will return only 1 ( yes or no )?
2) In the past I have had the RDBMS complainin: "only the first 1000 rows might be retrieved", this second approach would solve that problem?
3) What is the scope of the alias in the second subquery?... does the alias only lives in the parenthesis?
for example
select * from table t where exists (
select nameid from othertable o where t.nameid = o.nameid and otherdesc = 'SomeDesc' )
AND
select nameid from othertable o where t.nameid = o.nameid and otherdesc = 'SomeOtherDesc' )
That is, if I use the same alias ( o for table othertable ) In the second "exist" will it present any problem with the first exists? or are they totally independent?
Is this something Oracle only related or it is valid for most RDBMS?
Thanks a lot