i am starting with this table:
SELECT [Lab Occurrence Form].[Practice Code], [Lab Occurrence Form].[1 0 Preanalytical (Before Testing)], Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]) AS [CountOf1 0 Preanalytical (Before Testing)]
FROM [Lab Occurrence Form]
WHERE ((([Lab Occurrence Form].[Occurrence Date]) Between [Forms]![By Number]![Text4] And [Forms]![By Number]![Text2]))
GROUP BY [Lab Occurrence Form].[Practice Code], [Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]
HAVING ((([Lab Occurrence Form].[Practice Code])<>"") AND ((Count([Lab Occurrence Form].[1 0 Preanalytical (Before Testing)]))<>0));
it selects 3 columns but i need to aggregate the comments and put it in the fourth column where the first two values are the same
I want to perform a 'SELECT' statement with a byte array (binary) parameter as a condition.
I tried to google it, but didn't find anything useful.
In general, I keep information of files in the database. one of the properties is the file's hash (binary).
I want to give a hash to the SELECT statement, and get all rows with the same hash value.
I have a table of many values where one column has the WO Number, and another column has the Resource ID. I need to be able to find all the WO numbers that do not have a resource value of "RW".
Here is an example of the typical information. I need to be able to know that work order 5678 does not have an "RW" Resource ID.
WO Number - Resource ID
1234 - IN
1234 - WE
1234 - AS
1234 - RW
5678 - PR
5678 - WE
5678 - IN
5678 - AS
I apologize for the vague title. I am attempting to write a query that returns an alias column with matching values (resulting from an IN) as well as an alias column with values that do not match (using NOT IN). I want the result set to have: userId | matches | nonmatches. I currently have the following query which returns the matches as expected. I am having trouble getting the nonmatches in the result set -- that is, from a NOT IN statement
SET @userId = 9;
SELECT ug.user_id, COUNT(DISTINCT goal_id) as matches
FROM user_goal ug
WHERE ug.user_id!=@userId
AND goal_id IN (SELECT iug.goal_id FROM user_goal iug WHERE user_id=@userId)
GROUP BY user_id ORDER BY matches DESC LIMIT 4
So, the NOT IN would look something like this:
goal_id NOT IN(SELECT uggg.goal_id FROM user_goal uggg WHERE user_id=@userId) AS nonmatches
I am just not sure how to incorporate the NOT IN statement in my query so I get all the results
suppose I have tables Employee, Locations. and I have a view viewEmpLocation which is made by joining Employee and Locations.
Now If I update the view, will data in original table get updated.
I'm interested in finding the most precise decimal values in a database field. I'd like to be able to sort results by descending precision. Is this possible?
e.g.
10.1781253
12345.12435
89.763
1.1
2
Hi Guys,
I have a trigger that sends an email once a value has been changed.
It works when i make any amendments but when the users make the changes it fails.
I have figured out the users havnt got permission to send mails in master.dbo.xp_sendmail
The way the DB was originally setup wis shocking!! (each user has a network login rather than being part of a network group)
Is there anyway i can allow a role in customerDb to access the xp_sendmail proc in the mater db?
Thanks
Sp
I m passing a variable to stored procedure, i want the proc to make a look up to another table and get the primary key of the table and insert that value to the table.
Table A:
pk_id int,
user varchar
Table B:
userKey int
When i invoke sp_howto, and pass user to it, i want to it to get the pk_id from table A and insert it to table B userKey.
@res = select userKey from TableA where user=@user
insert into tableB (userKey) values (@res)
Does this work? and what if I have many keys I want to populate like this?
I have table 'products' and I need to update 'price' field by 20% if product 'type' field is "imported".
How do I read and update field at the same time in my UPDATE query?
CREATE OR REPLACE PROCEDURE p_createLocaltable
IS
table_already_exist EXCEPTION;
PRAGMA EXCEPTION_INIT (table_already_exist, -00955);
BEGIN
create table local_table as
select * from supplied_table
where rownum < 1;
EXCEPTION
when table_already_exist then
DBMS_OUTPUT.put_line('Table already exists , does not need to recreate it');
END;
can anyone see any problem of the above code?
I have a class User and a class History. History has 'User' property, and User has 'Histories' property. So there's a database relationship.
But when I create a new User history class and set UserID property, I can't access the 'User' property.
var history = new History { UserID = 1 };
// history.User = null ???
How can I get the user?
I have a table in my database. I want to get the maximum value of a column named NumOfView. I used this code:
var advert=(from ad in storedb.Ads where ad.AdScope == "1" select ad.NumOfView).Max();
It works but when there are two or more same maximum values it doesn't work and this message appears:
Sequence contains more than one element
What should I do now? Your answers will be very helpfull. Thanks
Hi, I'm here again-
I have something like this
Select A.a, A.b, A.a+A.b as c, (A.a+A.b*2)+A.d as d from Table
But i want to know, if it is possible, to make it work with something like this:
Select A.a,A.b,A.a+A.b as c, (c*2)+A.d as d from Table
Thank you
I'm trying to figure out the syntax for creating a view (or function) but only if a dependent CLR assembly exits.
I've tried both
IF EXISTS (SELECT name FROM sys.assemblies WHERE name = 'MyCLRAssembly')
begin
create view dbo.MyView as select GETDATE() as C1
end
and
IF EXISTS (SELECT name FROM sys.assemblies WHERE name = 'MyCLRAssembly')
create view dbo.MyView as select GETDATE() as C1
go
Neither work. I get
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword
'view'.
How can this be done?
I have a long running stored proc (approx 30 mins) which is currently running within a transaction (isolation level snapshot).
I've set the transaction to snapshot to avoid locking records preventing other processes from accessing the data.
What I'm trying to do is write to and read from a status table, but although we're in a transaction I'd like to write to and read from the status table as if I'm not in a transaction. I need this so that other processes can read any updates to this table by my stored proc, and this stored proc can also read any inserts made by other processes.
I realise that having my entire stored proc running within a transaction isn't recommended, but this has been done for other reasons and we need to stick with that approach.
So my question is within a transaction, is it possible to execute a query or call a stored proc which effectively isn't enlisted in the transaction?
[HttpPost]
public void Test(HttpPostedFileBase file)
{
UsersContext db = new UsersContext();
byte[] image = new byte[file.ContentLength];
file.InputStream.Read(image, 0, image.Length);
CrimeReport i = new CrimeReport
{
ImageId=1, ImageName="Anjli",ImageContent = image,
Active=true
};
db.CrimeReports.Add(i);
db.SaveChanges();
}
I am getting an exception on db.CrimeReports.Add(i);
Suppose I have a 2 column table (id, flag) and id is sequential.
I expect this table to contain a lot of records.
I want to periodically select the first row not flagged and update it. Some of the records on the way may have already been flagged, so I want to skip them.
Does it make more sense if I store the last id I flagged and use it in my select statement, like
select * from mytable where id > my_last_id order by id asc limit 1
or simply get the first unflagged row, like:
select * from mytable where flagged = 'F' order by id asc limit 1
Thank you!