|
The following code is used in the where clause in a stored procedure and will error when @ciDept = '4,25'. It works when @cilocn = '4'
tLD.idClientDeptNumb IN (CASE WHEN @ciDept <> '' THEN CONVERT(INT, @ciDept) ELSE tLD.idClientDeptNumb END
The error thrown is:
Syntax error converting the varchar value '4,25' to a column of data type int.
How can this error be resolved?
|
|
|
|
|
dptalt wrote: Syntax error converting the varchar value '4,25' to a column of data type int
decimal separator in SQL is dot. If you're unable to modify it on the calling side, you can use replace function to modify it in the stored procedure or in the statement.
Also integer cannot handle decimals so you should use for example real as datatype:
tLD.idClientDeptNumb IN (
CASE
WHEN @ciDept <> ''
THEN CONVERT(REAL, REPLACE(@ciDept, ',', '.'))
ELSE tLD.idClientDeptNumb
END...
But if you can, prefer using numeric variables if they contain numeric data.
|
|
|
|
|
Replacing ',' to '.' always returns 0 rows.
I thought the IN list command requires the elements in the list to be separated by commas?
If I do not replace the commas with decimals I get the following error:
Error converting data type varchar to real.
|
|
|
|
|
As in the other post from you, could it be because of other conditions. If it's not working, could you post the whole query.
|
|
|
|
|
Hi experts.
I have a basic question .
I'm going to create a local database for may WPF App, but I don't know which one is better, sdf database or mdf database.
I've searched , but couldn't find anything special.
Could you explain the differences between them ?
Thanks in advance.
|
|
|
|
|
mdf will require a Sql Server installation (can be express) while sdf will run without any database.
Mdf should have better performance since it runs on an actual database, but sdf will be much easier to deploy
|
|
|
|
|
|
Both are a real database file. .sdf file are called embedded database (the database server is just a class library that you access) so your application will become the database "server".
|
|
|
|
|
First: i'm sorry for my bad english
I've a problem,
in my webaplication, i use sqlite to manage some data for links
in a simple favourite links page. To get all links i use:
$connectionhandle = sqlite_open('mystart2', 0666, $sqliteerror);
$result = sqlite_query($connectionhandle, $query, SQLITE_ASSOC);
$result = sqlite_fetch_array($result);
print_r($result);
ok, the functions for connecting and doing the query are capsuled
in classes but i think that doesn't matter
This query returns just the first row from this table,
so just one row, but i'm sure that there exists at least 3 rows.
That means that the query should return 3 rows, not just one.
What's the problem?
modified on Friday, January 16, 2009 4:43 PM
|
|
|
|
|
Hi,
it may be wise to show us some code, the SQL line seems fine.
modified on Friday, January 16, 2009 8:57 AM
|
|
|
|
|
Hi all,
I have table with data in my database as follows
table name :sample (col 'ps' is primary key)
village ps val
1 1 56
1 2 67
1 3 65
1 4 70
2 5 74
2 6 64
2 7 32
3 8 46
3 9 56
4 10 64
My requirement is i have to get the Count of 'village' whose val > 60 and val < 60
for that i tried in the following way..(for finding avg 'val' of villages)
select sum(val)/count(ps) assessment from sample group by village
output:
assessment
66
56
59
54
But i need the count of above assessment values > 60 and < 60
i.e count of assessment > 60 , < 60
For that i tried in following way(i know i wrote wrong...but it gives you the idea what i am trying for)
select count(*) sample where (select sum(val)/count(ps) assessment from sample group by village) > 60
Please suggest me how to do that...
thanks in advance.
|
|
|
|
|
you need to use HAVING...
something like:
select sum(val)/count(ps) assessment from sample group by village HAVING sum(val)/count(ps) > 60
let me know if it helps
Intelligence is almost useless for those who have nothing else!
Email: caiokf@gmail.com
|
|
|
|
|
thank you for your suggestion.
I got it.
Its similar approach as you suggested.
select count(*) from sample group by village
having avg(value) > 60
select count(*) from sample group by village
having avg(value) < 60
|
|
|
|
|
Good Morning ALL
I want to Restore a database, i have the Following SP
Create PROCEDURE [dbo].[sp_RestoreDatabase]
@dbname char(32), -- the database name to restore as
@filename char(32),
@Results int OUTPUT
AS
set nocount on
declare @path char(256)
set @path = 'C:\DATABASES\' -- the location of the backuped up database file (on the SQL Server)
execute('sp_ClearDatabaseConnections ' + @dbname) --kill the existing connections to the current Database
-- Restore the database
RESTORE DATABASE @dbname
FROM DISK ='C:\DATABASES\'+ @filename
WITH MOVE 'TNGoedit_Data' TO 'C:\DATABASES\'+ @dbname + '.mdf' ,
MOVE 'TNGoedit_Log' TO 'C:\DATABASES\'+ @dbname + '_log.ldf',
REPLACE,RECOVERY;
-- Was the command successful or was there a problem
if ( (select @@Error) = 0 ) begin
SET @Results = 1
end
else begin
SET @Results = 0
end
When i Compile this SP i get the Following Error
Msg 102, Level 15, State 1, Procedure sp_RestoreDatabase, Line 27<br />
Incorrect syntax near '+'.
Where is my Problem
Thanks
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
vuyiswam@its.co.za
|
|
|
|
|
Do you have an extra comma at the end of this line:
MOVE 'TNGoedit_Log' TO 'C:\DATABASES\'+ @dbname + '_log.ldf',
|
|
|
|
|
No , the Problem points on the line that uses the "+" Sign
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
vuyiswam@its.co.za
|
|
|
|
|
There was a plus on that line too, but if you double click the error, which of those lines is highlighted?
|
|
|
|
|
It goes to this line
FROM DISK = @path + @filename
Thanks
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
vuyiswam@its.co.za
|
|
|
|
|
What happens if you first modify the variable and then use only it in the restore, like:
...
SET @filename = 'C:\DATABASES\'+ @filename
-- Restore the database
RESTORE DATABASE @dbname
FROM DISK = @filename
...
|
|
|
|
|
Now it moved and Targeted the Following lines
WITH MOVE 'TNGoedit_Data' TO @path + @dbname + '.mdf' ,
MOVE 'TNGoedit_Log' TO @path + @dbname + '_log.ldf',
Thanks
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
vuyiswam@its.co.za
|
|
|
|
|
Seems that the problem was found so try to do the same for all variables, like:
...
SET @movetarget1 = @path + @dbname + '.mdf'
...
WITH MOVE 'TNGoedit_Data' TO @movetarget1...
|
|
|
|
|
Thanks i have Change the SP to look like this and it compiled fine ,
Create PROCEDURE [dbo].[sp_RestoreDatabase] <br />
<br />
@dbname char(32), -- the database name to restore as<br />
@filename char(32),<br />
@Results int OUTPUT<br />
<br />
AS<br />
<br />
set nocount on<br />
<br />
declare @path char(64)<br />
declare @dbmdf char(64)<br />
declare @dbldf char(64)<br />
set @path = 'C:\DATABASES\' -- the location of the backuped up database file (on the SQL Server)<br />
<br />
execute('sp_ClearDatabaseConnections ' + @dbname) --kill the existing connections to the current Database<br />
<br />
SET @filename = 'C:\DATABASES\'+ @filename<br />
set @dbmdf = 'C:\DATABASES\' + @dbname + '.mdf'<br />
set @dbldf = 'C:\DATABASES\' + @dbname +'_log.ldf'<br />
-- Restore the database<br />
RESTORE DATABASE @dbname <br />
FROM DISK = @filename<br />
WITH MOVE 'TNGoedit_Data' TO @dbmdf ,<br />
MOVE 'TNGoedit_Log' TO @dbldf,<br />
REPLACE,RECOVERY;<br />
-- Was the command successful or was there a problem<br />
if ( (select @@Error) = 0 ) begin<br />
SET @Results = 1<br />
end<br />
else begin<br />
SET @Results = 0<br />
end
and i tested it like this
DECLARE @Results INT
EXEC [dbo].[sp_RestoreDatabase] 'oBookingUFS','oBookingUFS',@Results out
and i got the Following Error
<br />
Msg 3234, Level 16, State 2, Procedure sp_RestoreDatabase, Line 27<br />
Logical file 'TNGoedit_Data' is not part of database 'oBookingUFS '. Use RESTORE FILELISTONLY to list the logical file names.<br />
Msg 3013, Level 16, State 1, Procedure sp_RestoreDatabase, Line 27<br />
RESTORE DATABASE is terminating abnormally.
Thanks
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
vuyiswam@its.co.za
|
|
|
|
|
Are you sure that this is the logical file name 'TNGoedit_Data' or should it be for example 'TNGoedit'
You can verify the logical names using RESTORE FILELISTONLY[^]:
RESTORE FILELISTONLY
FROM DISK = 'C:\DATABASES\oBookingUFS';
|
|
|
|
|
Hello everyone,
Two basic questions about transactions,
1. For single SQL insert/update/delete statement, are there any needs or benefits to wrap into a transaction?
2. I wrote T-SQL like this,
BEGIN TRY
Begin Transaction
...
commit
END TRY
BEGIN CATCH
rollback
...
END CATCH
my question is, is it a must to call commit explicitly just before end try statement? Any means to commit transaction automatically after end try statement?
regards,
George
|
|
|
|
|
George_George wrote: For single SQL insert/update/delete statement, are there any needs or benefits to wrap into a transaction
It's always inside a transaction. Either implicit or explicit. If you don't want to be able to rollback the operation then it wouldn't matter, if you have logical error handling etc, then explicit transaction would be needed.
George_George wrote: is it a must to call commit explicitly just before end try statement? Any means to commit transaction automatically after end try statement
Basically commit point canbe anywhere, even at client side. However if you explicitely start a transaction, you have to explicitely end it. If you don't execute commit, database will roll back the transaction at the end of the session (unless other transaction handling is occurring after this transaction).
|
|
|
|