|
This example is based on the AdventureWorks database;
UPDATE HumanResources.Employee
SET Title = 'updateFromView'
WHERE EmployeeID IN (SELECT EmployeeID FROM HumanResources.vEmployee)
The select statement gets a list of ID's in the view. You can then update all the records in the table that have this particular ID. You'll need something to identify each record individually for this to work. If there isn't, then try to add the primary key to the view. If there is no primary key defined in the base-table, add an identity to fullfill this role.
Good luck
I are troll
|
|
|
|
|
Hi,
I have a table which looks like the following.
OriginalTable
OriginalTable_Id(pk) OriginalTable_Name(unique)
---------------------------------------------------
1 NewColumnName1
2 NewColumnName2
...
I need to make it look like this table below dynamically:
NewTable
NewTable_Id(pk) NewColumnName1 NewColumnName2 ...
---------------------------------------------------------------
I know I need to create a new tempory Table (using tempDB?), but I don't know how to get the values in the table to be the new column names.
I have this at the moment:
CREATE TABLE NewTable
(
NewTable_Id INT PRIMARY KEY,
???
)
???:
Would it be something like:
SELECT OriginalTable_Name FROM OriginalTable
Any tutorials or advice would be greatly appreciated.
Thanks in advance.
hmmm pie
|
|
|
|
|
Have a look at pivot clause here[^]
Regards,
Syed Mehroz Alam
My Blog
My Articles
Computers are incredibly fast, accurate, and stupid; humans are incredibly slow, inaccurate and brilliant; together they are powerful beyond imagination. - Albert Einstein
|
|
|
|
|
Brilliant, that's exactly what I was looking for thanks alot.
But how can I get the name of the columns dynamically.
eg.
The value is '198' so how can I make it the column name without knowing the value?
Edit:
Thanks again for your help.
Two minutes after posting this reply and Googleing 'Dynamic Pivots' I found this[^] which solved my problem.
Sorry for the inconvenience.
hmmm pie
modified on Wednesday, April 22, 2009 2:15 PM
|
|
|
|
|
Hi
I have a stored procedure that takes an XML as a parameter. The problem is that anyone could call it passing in any XML. How do i write the stored procedure so that the XML that it takes in as a parameter is based on a specific schema?
Thanks
Neil
|
|
|
|
|
Hi
I Made Setup from my C# program (that work's with Oracle 10g)
when I try to run this program - in different Computer, i got this error message:
unable to load dll 'OraOps10.dll'
what it can be ?
thank's in advance
|
|
|
|
|
Did you add the reference to OraOps10.dll to your project? Did you copied this library also to the output folder (where your app is located)?
|
|
|
|
|
|
Maybe you have to install some kind of oracle client at the target computer.
|
|
|
|
|
I think so, but which file's I need ?
|
|
|
|
|
|
Friends,
I want to connect MS-ACCESS database through asp.net C#(LOCALLY).
help
|
|
|
|
|
Help with what exactly? The connectionstring? The C# code? What provider?
Start here[^].
I are troll
|
|
|
|
|
Hi
i have image stored in the DB, i could retreive it and dispaly it the body of the report but when i try to view it the header i can not because is not allowed to reffrence to dataset feild in the header,
i tried the Convert.ToBase64String but it did not work for me, it does not give an error but nothing is displayed
so please can you help here
modified on Wednesday, April 22, 2009 2:58 AM
|
|
|
|
|
Hello. I want to save the RowCount returned value in a variable and want to print (+1 with 'A' prefix).
I created a variable as int.
declare @TotalIntRow as int
Now I'm unable to assign the returned value of rowcount in a variable.
i use these ..
@TotalIntRow = select Count(*) from Rcount
Error :- Msg 137, Level 15, State 2, Line 1
Must declare the scalar variable "@TotalIntRow".
set @TotalIntRow = select Count(*) from Rcount
Error : - Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'select'.
[I also tried to add a demo value , Set @TotalIntRow = 1; , but showing message number 137 as above mentioned]
How could I save the value in it.
|
|
|
|
|
Try this one;
DECLARE @TotalIntRow AS INT
SET @TotalIntRow = (SELECT COUNT(*)
FROM Rcount)
PRINT @TotalIntRow
Don't forget that the DECLARE statement should be used to declare the variable, before using it.
Hope this helps
I are troll
|
|
|
|
|
Awesome mate.
But I cant understand one thing, if I do these steps individually I got scalar error something. why so ? just curious about it. Ain't the values are stored permanently in it?
BTW.. If even I run the above scripts do the variable takes additional space or they get removed after application shutdown?
Begin
DECLARE @TotalIntRow AS INT
SET @TotalIntRow = (SELECT COUNT(*)
FROM Rcount)
print @TotalIntRow + 1
Insert into Rcount Values(@TotalIntRow)
End
I m getting my partial desired result. I want to add prefix 'A' with the result set .. When I did .. I got , can't convert (variable declared for storing A) to int data type..
|
|
|
|
|
Oh my god, I can't believe I did it..
Begin
DECLARE @TotalIntRow AS INT
SET @TotalIntRow = (SELECT COUNT(*)
FROM Rcount)
print @TotalIntRow + 1
Insert into Rcount Values('A'+ Convert(varchar, @TotalIntRow))
End
|
|
|
|
|
Well done dude
nt_virus wrote: But I cant understand one thing, if I do these steps individually I got scalar error something. why so ? just curious about it. Ain't the values are stored permanently in it?
Not permanent, they are 'lost' once the command is finished executing. (In this case, once it passes the END statement) That's also the reason why they can't be executed separate, they are interpreted as separate commands if you execute them line by line separately.
nt_virus wrote: BTW.. If even I run the above scripts do the variable takes additional space or they get removed after application shutdown?
They are gone as soon as the script (the complete collection of lines) are finished, unless you store them in a table somewhere. Most applications execute their script and close the connection to the database when done.
Good work
I are troll
|
|
|
|
|
I am using a piece of automation software called Taskcentre, this has it's own database. This morning we were having issues with the software and it turns out that an essntial table has been cleared of all data.
There are currently no backups for the database and all tasks that have been created over the past year are now gone unless i can find a way of restoring the database to 2 - 7 days ago.
I was wondering if anyone had any ideas.
David
|
|
|
|
|
Any audit tables you could use?
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
Hi Bob
How do you mean Audit table?
|
|
|
|
|
Is there any automatic auditing going on to record actions on the table - you know, who added/changed/deleted a record. If so, you may be able to recover your data that way. If there is nothing obvious you could contact the vendor and ask them if they have any suggestions. Otherwise, I'm afraid you have learnt the hard way that you should always do backups.
Bob
Ashfield Consultants Ltd
Proud to be a 2009 Code Project MVP
|
|
|
|
|
To add to Bob's reply. Not only should you always do backups you should also make sure you can restore them.
Once worked in a place that did backups every day. When a hard disk crashed they discovered that the backups would not restore. Three months accounts data lost and had to be manually re-entered from documents.
Regards
David R
|
|
|
|
|
Thank you for all of your replies, it seems that I have lost all of the data and as you said I have learnt the hard way that we should keep on top of ALL our backups. Thankfully it shouldn't take too long to recreate the tasks, just means by busy couple of months just got a whole lot busier.
Thanks again
David
|
|
|
|