hi guys,
I am getting result as decimal in storeprocedure.for eg:If iam getting result as 123.45
I want to split 123.45 to 123 and 45.Can any body help?
I'm trying to get the result of a COUNT as a column in my view.
Please see the below query for a demo of the kind of thing I want (this is just for demo purposes)
SELECT
ProductID,
Name,
Description,
Price,
(SELECT COUNT(*) FROM ord WHERE ord.ProductID = prod.ProductID) AS TotalNumberOfOrders
FROM tblProducts prod
LEFT JOIN tblOrders ord ON prod.ProductID = ord.ProductID
This obviously isn't working... but I was wondering what the correct way of doing this would be?
So I have a query, can someone let me know if it looks ok content wise?
"INSERT INTO ".TBL_MESSAGES." (NULL, 'Your ranking points have changed',
'Due to your recent activity, your ranking points have increased by $r', '2', '$u',
'0', '0', '0', '0', NULL, NULL, NULL, NULL, now())";
I can add further information if the query doesnt appear to have a problem?
Thanks
I have two querys. Query 1 gives me this result:
Day New_Users
01-Jan-12 45
02-Jan-12 36
and so on.
Query 2 gives me this result:
Day Retained_Users
01-Jan-12 33
02-Jan-12 30
and so on.
I want a new query that will join this together and read:
Day New_Users Retained_Users
01-Jan-12 45 33
02-Jan-12 36 30
Do I use some sort of outer join?
I want to retrieve the left 3 numbers from an integer to be stored in a table. For example, if the int is 1234567, I want to retrieve 123. I want the second number (123) to also be an int; I don't want to convert anything to a string.
(And yes, really I should be working with strings. But I don't have control over that aspect of the issue.)
Thank you!
The State field in our database is a mess. There was no validation when it was filled so we have everything from two letter abbreviations to full state names to misspelled state names to "test" and "xxxx", etc.
I am not going to try to handle everything, but for sure I want to fix the correct state names to abbreviations.
I have a list of valid state names and abbreviations, but I don't know how I can do this:
UPDATE Table SET State = ('AR','AK') WHERE (SELECT * FROM Table WHERE State IN ('Arkansas','Alaska'))
Basically, can I update a field to be something from a list by the location it is in another list?
Hi, i have a query that returns something like this.
ID | Company| Total_Money | no_items | count_Total_Money_For_Company
-----------------------------------------------------------
1 | A | 1000 | 1 | 2001
2 | A | 1001 | 0 | 2001
3 | B | 1001 | 1 | 5010
4 | B | 1002 | 1 | 5010
5 | B | 1003 | 1 | 5010
6 | B | 1004 | 1 | 5010
7 | B | 1000 | 1 | 5010
How can i add that column with the count for that company?
Hello
I have a server with live databases, and I have a test-server where I sometimes restore databases from the live one, to get fresh data. But this way I have to set up all the users again, I have about 4 different users with different permissions that need set again.
Is there some way to do this a better way without using detach and attach, since I cant take the databases offline on the live-server?
Prefered some thing I could run that "re-fills" the tables with fresh data. No need to redo stored procedures and rights.
/M
I have a contracts table:
contractId date price partId
1 20120121 10 1
2 20110130 9 1
3 20130101 15 2
4 20110101 20 2
The contract with greatest date being the active contract (don't blame me, I blame infor for creating xpps)
I need to create query to see only active contracts (one contract per part, the contract with highest date).
So the result of the query should be like this:
contractId date price partId
1 20120121 10 1
3 20130101 15 2
I am out of ideas here, I tried self joining the table, I tried aggregation functions, but I can't figure it out. If anyone would have any idea, please share them with me..
How do I design the database to calculate the account balance?
1) Currently I calculate the account balance from the transaction table
In my transaction table I have "description" and "amount" etc..
I would then add up all "amount" values and that would work out the user's account balance.
I showed this to my friend and he said that is not a good solution, when my database grows its going to slow down???? He said I should create separate table to store the calculated account balance. If did this, I will have to maintain two tables, and its risky, the account balance table could go out of sync.
Any suggestion?
EDIT: OPTION 2: should I add an extra column to my transaction tables "Balance".
now I do not need to go through many rows of data to perform my calculation.
Example
John buys $100 credit, he debt $60, he then adds $200 credit.
Amount $100, Balance $100.
Amount -$60, Balance $40.
Amount $200, Balance $240.
i have a parent report and it contains a two sub report.
* subreport: item
which get all fields from store procedure named spGetReportItem. like
ItemName ItemQuantity TotalItemCost
ab 4 45
dd 6 98
*subreport: Labour
which get all fields from store procedure named spGetReportLabour. like
labourName labourQuantity TotalLabourCost
ab 44 455
dd 63 986
i want to find the total of totalitemcost and total of totallabourcost and then want grandtotal of totalitemcost and totallabourcost.
i have seen many examples on internet in which shared variable is used in the formula bt the problem is that they have used the table but i m fetching data from stored procedure. so how can i access the stored procedure fields for calculation.
like i have seen that many have used:
shared numbervar total:=sum({tablename.ColumnName});
but i have used stored procedure instead of table so how could i find total of field that resultset returns from stored procedure..
plz give me answer as soon as possible..
i need it urgently.
thanks..
Hi I'm trying to output something like the following but am finding that there is a lot of code duplication going on.
| australian_has_itch | kiwi_has_itch |
| yes | no |
| no | n/a |
| n/a | no |
...
My query looks like this with two case statements that do the same thing but flip the country (my real query has 5 of these case statements):
SELECT
CASE
WHEN
NOT EXISTS (
SELECT person_id
FROM people_with_skin
WHERE people_with_skin.person_id = people.person_id
AND people.country = "Australia"
)
THEN 'N/A'
WHEN
EXISTS (
SELECT person_id
FROM itch_none_to_report
WHERE people.country = "Australia"
AND person_id = people.person_id
)
THEN 'None to report'
WHEN
EXISTS (
SELECT person_id
FROM itchy_people
WHERE people.country = "Australia"
AND person_id = people.person_id
)
THEN 'Yes'
ELSE 'No'
END australian_has_itch,
CASE
WHEN
NOT EXISTS (
SELECT person_id
FROM people_with_skin
WHERE people_with_skin.person_id = people.person_id
AND people.country = "NZ"
)
THEN 'N/A'
WHEN
EXISTS (
SELECT person_id
FROM itch_none_to_report
WHERE people.country = "NZ"
AND person_id = people.person_id
)
THEN 'None to report'
WHEN
EXISTS (
SELECT person_id
FROM itchy_people
WHERE people.country = "NZ"
AND person_id = people.person_id
)
THEN 'Yes'
ELSE 'No'
END kiwi_has_itch,
FROM people
Is there a way for me to condense this somehow and not have so much code duplication?
Thanks!
I have a table like this
UserID Score Date
5 6 2010-1-1
7 8 2010-1-2
5 4 2010-1-3
6 3 2010-1-4
7 4 2010-1-5
6 1 2010-1-6
I would like to get a table like this
UserID Score RunningTotal Date
5 6 6 2010-1-1
5 4 10 2010-1-3
6 3 3 2010-1-4
6 1 4 2010-1-6
7 8 8 2010-1-2
7 4 12 2010-1-5
Thanks!
Asking a simple question, just want everyone have fun to solve it.
I got 2 tables.
1. Student
2. Course
Student
+----+--------+
| id | name |
+----+--------+
| 1 | User1 |
| 2 | User2 |
+----+--------+
Course
+----+------------+------------+
| id | student_id | course_name|
+----+------------+------------+
| 1 | 1 | English |
| 2 | 1 | Chinese |
| 3 | 2 | English |
| 4 | 2 | Japanese |
+----+------------+------------+
I would like to get the result all student, who have taken English and Chinese, NOT English or Chinese.
Expected result:
+----+------------+------------+
| id | student_id | course_name|
+----+------------+------------+
| 1 | 1 | English |
| 2 | 1 | Chinese |
+----+------------+------------+
What we normally do is
select * from student join course on (student.id = course.student_id) WHERE course_name = 'English' OR course_name = 'Chinese'
but in this result I can get User2 record which is not my expected result. I want the record only display the User take the course English+Chinese only.
Hi All,
I have a source column with blank (not "NULL"), and target as numeric. while converting using the data conversion it is not converting due to balnk source value so I used derived column to replace a blank value with NULL or 0 as
(source column == " ") ? "0" : source column
but its not giving the value as 0 in the blank place.
thanks
prav
Hello,
I have a stored procedure
DECLARE cursor FOR SELECT [FooData] From [FooTable];
OPEN cursor ;
FETCH NEXT FROM cursor INTO @CurrFooData;
WHILE @@FETCH_STATUS = 0
BEGIN
SELECT @CurrFooData AS FooData;
INSERT INTO Bar (BarData) VALUES(@CurrFooData);
FETCH NEXT FROM cursor INTO @CurrFooData;
END;
CLOSE cursor
DEALLOCATE cursor
But in result I have a lot of tables, not one. How can I return one table with 'FooData' column and all '@CurrFooData' rows?
Requirements:
tiny WinForms client app (C# 4.0, WinForms or WPF)
a few users working simultinausly
no database service at all - the whole engine as *.DLLs inside client
apps
database available as shared folder on one computer
at least simple concurrrency checks
compatible with nHibernate or EntityFramework / NET 4.0
backup as simple as copying files from shared folder - assuming no
running clients at the moment
no stored procedures/triggers required
data size - a few tables and a few thousands rows after 2 years
Nice to have:
user access rights
encrypted data
I'm trying to choose between:
MS Access
SqlLite
SqlServer Compact Edition.
Can you recommend which one should be the best for these requirements?
I’m trying to design a database to use with ASP.net MVC application. Here is the scenario: There are three entities and users can post their comments for each of these different entities. I just wonder how just put one table for Comments and link all other entities to it. Obviously, Comments table needs 3 references (foreign key) to those tables but as you know these foreign keys can’t be null and just one of them can be filled for each row. Is there any better way than implementing three different tables for each entity’s comments?
Hello, I have a table with measures and the time this measures have been taken in the following form: MM/DD/YYYY HH:MI:SS AM. I have measures over many days starting at the same time every day.The datas are minute by minute so basically the seconds are always = 0. I want to select only the measures for the first 5 minutes of each day. I would have used the where statement but the condition would only be on the minutes and note the date is there a way to do this?
Thanks
HI, i have two tables
1- name, id, code
2- id, value, concept
One name can have two concepts and two values. i want to retreive this:
Id, name, value1, value2.
How can i do that?
Tanks
I have a table for logging that needs a log ID but I can't use an identity column because the log ID is part of a combo key.
create table StuffLogs
{
StuffID int
LogID int
Note varchar(255)
}
There is a combo key for StuffID & LogID.
I want to build an insert trigger that computes the next LogID when inserting log records. I can do it for one record at a time (see below to see how LogID is computed), but that's not really effective, and I'm hoping there's a way to do this without cursors.
select @NextLogID = isnull(max(LogID),0)+1
from StuffLogs where StuffID = (select StuffID from inserted)
The net result should allow me to insert any number of records into StuffLogs with the LogID column auto computed.
StuffID LogID Note
123 1 foo
123 2 bar
456 1 boo
789 1 hoo
Inserting another record using StuffID: 123, Note: bop will result in the following record:
StuffID LogID Note
123 3 bop
I need to retrieve all records ordered alphabetically. Except for a predefined list of record's columns which their records should appear first in a given predefined order, then all other records should be sorted alphabetically based on the same column
For instance, assume we have the following table which is called Names
Lets assume the predefined list is ("Mathew", "Ashraf", "Jack"). I.e. these are the names of whom their records should be listed first as in the predefined order.
So the desired query result should be:
Which query could retrieve this custom order ?
P.S, I'm using MySQL.
Here's my trial based on comments' request:
(SELECT * FROM Names WHERE Name in ('Mathew', 'Ashraf', 'Jack'))
UNION
(SELECT * FROM Names WHERE Name NOT IN ('Mathew', 'Ashraf', 'Jack') ORDER BY Name ASC);
the first query result wasn't ordered as required.
I have two tables reports and holidays.
reports: (username varchar(30),activity varchar(30),hours int(3),report_date date)
holidays: (holiday_name varchar(30), holiday_date date)
select * from reports gives
+----------+-----------+---------+------------+
| username | activity | hours | date |
+----------+-----------+---------+------------+
| prasoon | testing | 3 | 2009-01-01 |
| prasoon | coding | 4 | 2009-01-03 |
| prasoon | coding | 4 | 2009-01-06 |
| prasoon | coding | 4 | 2009-01-10 |
+----------+-----------+---------+------------+
select * from holidays gives
+--------------+---------------+
| holiday_name | holiday_date |
+--------------+---------------+
| Diwali | 2009-01-02 |
| Holi | 2009-01-05 |
+--------------+---------------+
Is there any way by which I can output the following?
+-------------+-----------+---------+-------------------+
| date | activity | hours | holiday_name |
+-------------+-----------+---------+-------------------+
| 2009-01-01 | testing | 3 | |
| 2009-01-02 | | | Diwali |
| 2009-01-03 | coding | 4 | |
| 2009-01-04 | Absent | Absent | |
| 2009-01-05 | | | Holi |
| 2009-01-06 | coding | 4 | |
| 2009-01-07 | Absent | Absent | |
| 2009-01-08 | Absent | Absent | |
| 2009-01-09 | Absent | Absent | |
| 2009-01-10 | coding | 4 | |
+-------------+-----------+---------+-------------------+
In other words I want to fill the activity and hours columns with "Absent" on the dates which are neither in table reports nor in table holidays. How can I write a specific query for it. The query should give the output between two specific dates.
I have a table in db2 which has the following fields
int xyz;
string myId;
string myName;
Example dataset
xyz | myid | myname
--------------------------------
1 | ABC.123.456 | ABC
2 | PRQS.12.34 | PQRS
3 | ZZZ.3.2.2 | blah
I want to extract the rows where myName matches the character upto "." in the myId field. So from the above 3 rows, I want the firs 2 rows since myName is present in myId before "."
How can I do this in the query, can I do some kind of pattern matching inside the query?