|
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
|
|
|
|
|
Good Day All
I have Used Red Gate to Synchronise the SQl Database in 200 and the other in 2005. and it went well, now i have a SP that is Running in my application that restores the Database like this
RESTORE DATABASE LOV FROM DISK = 'C:\DATABASES\MasterDatabase'
WITH MOVE 'oBooking_Data' TO 'C:\DATABASES\LOV.mdf',
MOVE 'oBooking_Log' TO 'C:\DATABASES\LOV_log.ldf',
REPLACE,RECOVERY;[/
Now My Application Halt and gives me the Following Error, i have tried to run it manually from the T-SQL and i got this
Processed 368 pages for database 'LOV', file 'oBooking_Data' on file 1.
Processed 1 pages for database 'LOV', file 'oBooking_Log' on file 1.
Converting database 'LOV' from version 539 to the current version 611.
Database 'LOV' running the upgrade step from version 539 to version 551.
Database 'LOV' running the upgrade step from version 551 to version 552.
Database 'LOV' running the upgrade step from version 552 to version 553.
Database 'LOV' running the upgrade step from version 553 to version 554.
Database 'LOV' running the upgrade step from version 554 to version 589.
Database 'LOV' running the upgrade step from version 589 to version 590.
Database 'LOV' running the upgrade step from version 590 to version 593.
Database 'LOV' running the upgrade step from version 593 to version 597.
Database 'LOV' running the upgrade step from version 597 to version 604.
Database 'LOV' running the upgrade step from version 604 to version 605.
Database 'LOV' running the upgrade step from version 605 to version 606.
Database 'LOV' running the upgrade step from version 606 to version 607.
Database 'LOV' running the upgrade step from version 607 to version 608.
Database 'LOV' running the upgrade step from version 608 to version 609.
Database 'LOV' running the upgrade step from version 609 to version 610.
Database 'LOV' running the upgrade step from version 610 to version 611.
RESTORE DATABASE successfully processed 369 pages in 0.204 seconds (14.782 MB/sec).
Thank you
Vuyiswa Maseko,
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.tiyaneProperties.co.za
vuyiswa@its.co.za
http://www.itsabacus.co.za/itsabacus/
|
|
|
|
|
Hi to all,
I have a mail table with the fields like id,to,receiver,subject,description,date etc..
when i fill the to field with multiple receipient seperated by comma, i want to store in the table for all members.
How it is possible?
|
|
|
|
|
So split the recipeints by comma and repeat the insert for each one.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Yes. Can u tell how to split and insert for each receipient?
|
|
|
|
|
I just did, split the recipients using text.split
Insert each record using your current insert method, changing the recipeint each time.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I cant get.Can u describe briefly?
|
|
|
|
|
What are you doing over here - go back to the ASP forum where they may have more patience with fools - you obviously have no idea what you are doing.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Dear All,
I am looking for the best data modeling tool,
Objective: I have an SQL database up and running, i want to have the best tool in order to architecture and document my DB.
Regards,
Muhammad Nauman
"Mess with the Best, Die like the rest"
|
|
|
|
|
Try googling for "database reverse engineering" - 400K+ hits.
Regards
David R
|
|
|
|
|
Try D-Softs database compare tool
|
|
|
|
|
Hi, I have been trying this for two days.
Is it possible to load the calculated Excel fields in to dataset.
I am using Ado.Net and Oledb to read excel.
Thanks,
Nagaraj
|
|
|
|
|
What is calculated excel fields?
|
|
|
|
|
Excel cell which is having Excel Formula instead of value.
Thanks,
Nagaraj
|
|
|
|
|
We've used Intellisync in the past for synchronizing databases ... they've basically gone out of busines, and I'm interested in knowing what software others use to synchronize ms sql databases.
The software has to be capable of implementing rules for synchronization, so I can sync select data / tables.
Thanks!
Paul Brower
|
|
|
|