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?
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 maintain a product that is installed at multiple locations which as been haphazardly upgraded. Unique constraints were added to a number of tables, but I have no idea what the names are at any particular instance. What I do know is the table/columnname pair that has the unique constraints and I would like to write a script to delete any unique constraint on these column/table combinations. This is MSSQL 2000 and later. Something that works on 2000/2005/2008 would be best!
I have data in a table, but am working on data loading. I want to reseed all new inserts for testing.
What would be the line to set all new inserts to a certain seed value?
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?
What's the Correct or most popular name for a Association table? I've heard Lookup,associative,resolving,mapping and junction table so far?
Thank you in advance;-)
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 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'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
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
[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);
Call me pedantic but is there a more elegant way to combine all those checks?
SELECT * FROM [TABLE1]
WHERE [path] = 'RECEIVE'
AND [src_ip] NOT LIKE '10.48.20.10'
AND [src_ip] NOT LIKE '0.%'
AND [src_ip] NOT LIKE '127.%'
ORDER BY [date],[time] DESC;
To something like this:
SELECT * FROM [TABLE1]
WHERE [path] = 'RECEIVE'
AND [src_ip] NOT LIKE IN ('10.48.20.10','0.%','127.%', .... )
ORDER BY [date],[time] DESC;
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.
How can I do a search for value A in column1 and add a value B in column2?
In other words for every record that column1 has the value A I want to make the value in column2 = B (Currently column2 is empty)
Would this work?
UPDATE MyTable
SET Column2 = REPLACE(Column2,NULL,'B')
WHERE Column1 = "A"
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
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 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
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?