Alter script not working on server [closed] - sql

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have an alter script to change datatype from nvarchar to float which works fine in my local machine but fails to work on 2012 server.
Can anybody tell me what's wrong with my script or any changes need to be done on server?
My alter script is as follows:
ALTER TABLE mytable
ALTER COLUMN mycolumn FLOAT
and I get this error:
Msg 8114, level 16,state 5, line 6
Error converting datatype nvarchar to float

If it is throwing an error 'Error converting data type varchar to float.' then it is obvious that there are some values in the varchar field which cannot be converted to float. If you can tell us more about the error being thrown, it will be easier to understand the issue.

Related

SQL Insert Query With Condition Exception [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 12 months ago.
Improve this question
I have this query:
String requete = "INSERT INTO reduction(newPrix) VALUES (?) "
+ "WHERE id_prom=? AND id_prod=?";
I am getting an exception:
You have an error in your SQL syntax; check the manual that
corresponds to your MariaDB server version for the right syntax to use
near 'WHERE id_prom=2 AND id_prod=6' at line 1
I'm wondering why the INSERT query was failing. Any advise appreciated.
You insert a row into your table.
This means that you need to specify all mandatory values (i.e. values for the columns that are not nullable and don't have a default value).
You can't use a where clause in this kind of insert statement. What would it mean? And in your program you can verify the validity of the data you'd like to add to your table and decide to insert or not.

How to use sp_depends for other database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Using SQL Server 2010
For updating the tables i am using following line
update database1_ab..table1
For sp_depends i am getting error as "Incorrect syntax near '.'"
sp_depends database1_ab..table1
How to use sp_depends for referring other database tables in current database
regardless, you need to put it in single quotes... ie
sp_depends 'database1_ab..table1'
or
sp_depends '[database1_ab]..[table1]'
You can call all the sp_ -procedures also in different database like this:
database1_ab..sp_depends table1

Getting error The conversion of a varchar data type to a datetime data type resulted in an out-of-range value. The statement has been terminated [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
this is my code
sqlcommand=new sqlcommand("inset into table values('"+home.name'"+,'"+home.DOJ'")",con);
You're using the local default string conversion from DateTime (I assume) to string, and then hoping that's valid for SQL.
Additionally, your code has a SQL injection attack vulnerability.
Both of these can be fixed - and your code readability - can be improved using parameterized SQL:
using (var command = new SqlCommand(
"INSERT INTO Foo (Name, DOJ) Values (#Name, #DOJ)", connection))
{
command.Parameters.Add("#Name", SqlDbType.VarChar).Value = home.name;
command.Parameters.Add("#DOJ", SqlDbType.DateTime).Value = home.DOJ;
...
}
(Adjust the types accordingly, e.g. using SqlDbType.NVarChar and SqlDbType.DateTime2.)
Never put values directly into SQL like you were doing. Using parameterized SQL is a win all round.

SQL Fiddle - date format not recognized [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
So as someone advised me yesterday I'm using SQL Fiddle since it's an easy way to test database queries and SQL programming in general but I'm getting this error:
Schema Creation Failed: ORA-01821: date format not recognized
This happens in the insert line. This usually works in Oracle and I selected in the combobox on top of the page Oracle 11g. So what's the problem?
create table Reparacoes(
numero_r int,
matricula char(8),
dataEntrada date,
constraint pk_carro primary key(numero_R),
constraint check_matricula check (regexp_like(matricula,'[[:number:]]{2}-[[:alpha:]]{2}-[[:number:]]{2}')));
insert into Reparacoes values (1,'S2-SS-12',to_date('yyyy-mm-dd','2013-11-10'));
By my own stupidity I was using the to_date wrongly. It's supposed to be like this:
to_date('2013-11-10','yyyy-mm-dd'));
and not like this:
to_date('yyyy-mm-dd','2013-11-10'));

Error message from simple SELECT statement with practice database [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I use the AdventureWorks practice database attached to SQL Server 2012.
A simple statement like:
SELECT * FROM HumanResources.Shift;
gives me this error:
Msg 208, Level 16, State 1, Line 1
Invalid object name 'AdventureWorks2012'.
I also tried:
USE master
GO
SELECT * FROM HumanResources.Shift;
Received same error message. Any idea to why this is happening?
Is AdventureWorks2012 the name of a database or a table?
USE <database name>
means use the specified database to run the query against.
SELECT * FROM <table name>
means select all the rows from the specified table.
--Edit because of change in question--
You don't want to use Master, you want to use the name of your DB. Next, using the object explorer, I would make sure the table actually exists in the Database you created.