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?
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?
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?
Say I have the simple table below:
KeyWordID KeyWord
----------- ----------
1 Blue
3 Yellow
1 Yellow
How would I select the KeyWordID that selects the KeyWordIDs that where both KeyWord is Blue and Yellow.
E.g. it should only return 1, as this is the only KeyWordID that has both Keywords Blue and Yellow
I initially thought GROUPBY - but its not quite working as expected.
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
Which is better and what is the difference?
SELECT * FROM TABLE_A A WHERE A.ID IN (SELECT B.ID FROM TABLE_B B)
or
SELECT * FROM TABLE_A A, TABLE_B B WHERE A.ID = B.ID
I have a stupid question, I have this table :
id_product name value
1 price 10-20
1 type computer
2 price 20-30
3 price 100-200
and I want to select from this table GROUP BY id_product and ORDER BY value WHERE name='price'
how can i do this?
Thanks a lot
Hello,
i got a MySql DB.
There is a table with products and orders.
Structure:
Products: product_id, name, manufacturers_id
Orders: orders_id, product_id, quantitiy
Now I want to get all orders (show only products where product id=1).
I tried:
SELECT
orders.orders_id,
orders.product_od
FROM products, orders
WHERE products.manufacturers_id = 1
GROUP BY orders_id
ORDER BY orders_id
But this doesnt work
I haven't spent a ton of time researching this yet, mostly looking for best practices on upgrading/changing DB schemas.
We're actively developing a new product and as such we often have additions or changes to our DB schema. We also have many copies of the DB -- one for the test environment, one for the prod environment, dev environments, you name it. We don't really want to have to blow away test data every time we want to make a change to the DB.
Are there good ways of automating this or handling this? None of us have really ever had to deal with this so...
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
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
Guys is there any better way to list all the months other than this
select to_char(add_months(to_date('01/01/1000', 'DD/MM/RRRR'), ind.l-1),
'MONTH') as
month_descr
, ind.l as month_ind
from dual descr
, (
select l
from (select level l from dual connect by level <=
12)
) ind
order by 2;
ANSWER :
SELECT to_char(add_months(SYSDATE, (LEVEL-1 )),'MONTH') as months FROM dual CONNECT BY LEVEL <= 12
I have a select statement and I wish to calculate the cubic volume based on other values within the table. However I want to check that neither pr.Length_mm or pr.Width_mm or pr.Height_mm are NULL prior. I've looked at CASE statements, however it only seems to evaluate one column at a time.
SELECT
sa.OrderName,
sa.OrderType,
pr.Volume_UOM
,pr.Length_mm*pr.Width_mm*pr.Height_mm AS Volume_Cubic
,pr.Length_mm*pr.Width_mm AS Volume_Floor
,pr.Length_mm
,pr.Height_mm
,pr.Width_mm
FROM CostToServe_MCB.staging.Sale sa
LEFT JOIN staging.Product pr
ON sa.ID = pr.ID
I have a stored procedure that is called by a website to display data. Today the web page has started timing out so I got profiler going and saw the query that was taking too long. I then ran the same query in management studio, under the same user login, and it takes less than a second to return.
Is there anything obvious that could be causing this? I can't think of a reason why when ASP calls the stored proc it takes 30 secs but when I call it it's fine.
Thanks
HI !
This is my table:
CREATE TABLE [ORG].[MyTable](
..
[my_column2] UNIQUEIDENTIFIER NOT NULL CONSTRAINT FK_C1 REFERENCES ORG.MyTable2 (my_column2),
[my_column3] INT NOT NULL CONSTRAINT FK_C2 REFERENCES ORG.MyTable3 (my_column3)
..
)
I've written this constraint to assure that combination my_column2 and my_column3 is always unique.
ALTER TABLE [ORG].[MyTable] ADD
CONSTRAINT UQ_MyConstraint UNIQUE NONCLUSTERED
(
my_column2,
my_column3
)
But then suddenly.. The DB stopped responding.. there is a lock or something..
Do you have any idea why?
What is bad with the constraint?
I have a trigger which deals with some data for logging purposes like so:
CREATE TRIGGER trgDataUpdated
ON tblData FOR UPDATE
AS
BEGIN
INSERT INTO tblLog ( ParentID, OldValue, NewValue, UserID )
SELECT deleted.ParentID, deleted.Value, inserted.Value,
@intUserID -- how can I pass this in?
FROM inserted INNER JOIN deleted ON inserted.ID = deleted.ID
END
How can I pass in the variable @intUserID into the above trigger, as in the following code:
DECLARE @intUserID int
SET @intUserID = 10
UPDATE tblData
SET Value = @x
PS: I know I can't literally pass in @intUserID to the trigger, it was just used for illustration purposes.
I have the next query that in my opinion is a valid one, but I keep getting error telling me that there is a proble on "WHERE em.p4 = ue.p3" - Unknown column 'ue.p3' in 'where clause'.
This is the query:
SELECT DISTINCT ue.p3
FROM
table1 AS ue INNER JOIN table2 AS e
ON ue.p3 = e.p3
WHERE
EXISTS(
SELECT 1 FROM (
SELECT (COUNT(*) >= 1) AS MinMutual
FROM table4 AS smm
WHERE
smm.p1 IN (
SELECT sem.p3 FROM table3 AS sem
INNER JOIN table2 AS em ON sem.p3 = em.p3
WHERE em.p4 = ue.p3 AND
sem.type = 'friends' AND em.p2 = 'normal' ) AND
smm.p5 IN (
15000,15151
)
) AS Mutual WHERE
Mutual.MinMutual = TRUE) LIMIT 11
If I execute the sub-query which is inside the EXISTS function, everything is O.K.
PLEASE HELP!
Hi, this is what I want to achieve:
4 tables are involved:
Players with PlayerID as PK,
Competitions with CompetID as PK
Results with ResultID as PK and CompetID as FK
And the 4th table: PlayerResultts with ResultID + PlayerID as PK and CompetID as new column I created.
Competitions, results and PlayerResults are already populated and quite large (300000 PlayerResults so far).
In order to populate the PlayerResults.CompetID column, I try a Update ... (Select....) request but I'm not aware of the right syntax and it fails.
Here is my feeble attempt:
update PlayerResults
set competid = (select distinct(r.competid) from results r, playerresults p
where r.resultID = p.resultid)
Error is (of course):
"Msg 512, Level 16, State 1, Line 1
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , , = or when the subquery is used as an expression."
Can someone put me in the right direction? TIA
Hi
I have 2 tables A and B with the following columns
Table A - id,bId,aName,aVal
Table B - id,bName
where A.bId is the same as B.id. I want a result set from a query to get
A.id, A.aName, B.bName where A.bId=B.id OR
A.id, A.aName, "" when A.bId=0.
In both cases, only those records should be considered where A.aVal LIKE "aVal"
Can someone please help me with the query? I can use left join but how do I get the blank string if bId=0 and B.bName otherwise?
Thanks
Trying to finish up some homework and ran into a issue for creating tables. How do you declare a column default for a range of numbers. Its reads: "Column Building (default to 1 but can be 1-10)" I can't seem to find ...or know where to look for this information.
CREATE TABLE tblDepartment
(
Department_ID int NOT NULL IDENTITY,
Department_Name varchar(255) NOT NULL,
Division_Name varchar(255) NOT NULL,
City varchar(255) default 'spokane' NOT NULL,
Building int default 1 NOT NULL,
Phone varchar(255)
)
I tried Building int default 1 Between 1 AND 10 NOT NULL, that didn't work out
I tried Building int default 1-10, the table was created but I don't think its correct.
Sorry - my question title is probably as inept at my attempt to do this.
I have the following (well, similar) in a table in a CMS
pageID key value
201 title Page 201's title
201 description This is 201
201 author Dave
301 title Page 301's title
301 description This is 301
301 author Bob
As you've probably guessed, what I need is a query that will produce:
pageID title description author
201 Page 201's title This is page 201 Dave
301 Page 301's title This is page 301 Bob
If anybody could help, i'd be eternally grateful - I know this is "please send me the code" but I'm absolutely stuck.
Thanks in advance.
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..