Trying to change some of the rows in a table specifically one column. column type is varchar ex. of data current desired $345,434.0 345434.0 (stripping out of $ & commas) 435.0 leave as is general txt leave as is
having trouble updating data in table tried using temp table, but update command make it so it won't see table
ex. piece of code update currency_conversion set currency_varchar = cast (cast (currency_varchar as money)as varchar) select * from currency_conversion where substring (currency_varchar from 1 for 1) = '$' ;
I was wondering how to modify a column's properties, like its datatype or length.
I know I'm supposed to do something like this: ALTER TABLE MyTable ALTER COLUMN MyColumn int(20)
My main concern is, what will the database do to all the data in the column, if the column used to be, say nvarchar(50)? Will I lose the data in the column if I change the datatype? And what if I had data in this column that was longer than 20 characters? Will the data now be truncated? What can I do to make sure that nothing happens to the data once I change the datatype?
DECLARE @strComma VARCHAR(1000) SET @strComma = 'cmpnt_name,ASC,1,2' SELECT CAST(RIGHT(LEFT(@strComma,Number-1), CHARINDEX(',',REVERSE(LEFT(','+@strComma,Number-1)))) AS CHAR(30)) FROM master..spt_values WHERE Type = 'P' AND Number BETWEEN 1 AND LEN(@strComma)+1 AND (SUBSTRING(@strComma,Number,1) = ',' OR SUBSTRING(@strComma,Number,1) = '')
however i getting the data in one field which is like
cmpnt_name ASC 1 2
i would like them to be in their specific column that is 4 different field
We have a "main" SQL 2014 server who imports XML files using SSIS in a datacenter. In remote sites (which are warehouses), there is an instance of SQL 2014 Express. A merge replication is setup, as every operations done on each site must be "forwared" to the main database, as some XML files are generated as output for an ERP system.
Now, the merge replication replicate all the data to the server on each sites. But a specific site don't need the data of every other sites, only the data relevant to itself (which is the warehouse code). Is there a way to replicate only the data relevant to each individual sites to the subscribers? Or is there a better way than replication to accomplish this?
Hi guys, If I have a temporary table called #CTE With the columns [Account] [Name] [RowID Table Level] [RowID Data Level] and I need to change the column type for the columns: [RowID Table Level] [RowID Data Level] to integer, and set the column [RowID Table Level] as Identity (index) starting from 1, incrementing 1 each time. What will be the right syntax using SQL SERVER 2000?
I am trying to solve the question in the link below: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2093921&SiteID=1
Thanks in advance, Aldo.
I have tried the code below, but getting syntax error...
ALTER TABLE #CTE ALTER COLUMN [RowID Table Level] INT IDENTITY(1,1), [RowID Data Level] INT;
I have also tried:
ALTER TABLE #CTE MODIFY [RowID Table Level] INT IDENTITY(1,1), [RowID Data Level] INT;
I am very early on in developing a website to track issues with projects which is tied to a SQL database. I have my Projects Table, my Users Table, and am creating a third table to track issues. I'm wondering what is the best way to assign specific users to specific data/projects. The user should only be able to view & update the projects assigned to him. He should not be able to see other projects. What is the best way to assign projects/data to the users to make sure they are only viewing their data?
I initially modified the column 'ID' from not allowing NULL to allow, and saved it. But now I will like to change it back to 'not allow'. But it gives me the following error message when I try to save my changes:
'Pages' table - Unable to modify table. Cannot insert the value NULL into column 'ID', table <databasename>.Tmp_Pages'; column does not allow nulls. INSERT fails. The statement has been terminated.
using sql database, i have a smallmoney column. when i enter an amount, 50.00 for example, i have 50.0000 displayed. is there a way to only have 50.00 displayed? same with the smalldatetime, is there a way to limit the display to "mm/dd/yyyy" without the "hh:mms am"
I have a column that is a currently set as nvarchar(50) and is called DateEmployed. There are over a hundred rows that contain dates which is in nvarchar format.
This column now needs to be changed to a DateTime datatype. (Don't ask me it was not set to a dateTime when this was first designed - I wasn't here)
However, I have to change this column to a DateTime without destroying the data.
Is there any easy way to write some script or use studio management to change this.
Currently the data is displayed like this in this column dd/MM/yyyy i.e. 25/8/2007.
The method I am using to try and change this is by going to studio management clicking modify on the column and changing the datatype from a nvarchar(50) to a DateTime.
I get this following error message: - Unable to modify table. Arithmetic overflow error converting expression to data type datetime. The statement has been terminated.
sorry all help does not work , if the value like this
table = test
magusageid playid msgtype mchangeprice ------------- --------- ---------- --------------- 35 6 a 400 36 8 a 450
====================================== and other question is if magusageid is use int IDENTITY(1,1) how can i edit char in my magusageid which like this magusageid playid msgtype mchangeprice ------------- --------- ---------- --------------- A000_35 6 a 400 A000_36 8 a 450
sorry the question is when i insert one row into this table and the data type my want to auto increase 1 to z in sql i can use IDENTITY this data type to increas but the column of data use only number without char so i need to know how can i use IDENTITY + char to save data into one row thank's
I have created a DB and up until yesterday I have been using SQL commands to add/remove tables, columns, constraints etc. However today when I attempt to modify the datatype of a column using
alter table Person modify Gender nchar(2)
I get this error
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'modify'.
I can still add colums but get the same error if I try to drop them and I can amend the tables in any way via the Design view so I don't think it's permission related.
Hi All, Is there a way by which we can modify the width of a column of a table which is being replicated without touching the ongoing transactional replication? This is for MSSQL2000 Transactional Replication.
I know (and successfully tried) that we can add a column to a table and that gets propaged to the replicate database and indeed the added column gets reflected there. How to add a column? sp_repaddcolumn or Right Click on the Publication-Properties and it shows a button to Add a Column.
This is what I have tried for modifying the width of a column of a table participating in Transactional Replication from varchar(10) to varchar(100)
MH (source) -> MH1 (Replicate)
The column €œcol1€? had width of varchar(10) and this was altered to varchar(100).
How do I modify data in a sqlDataSource object (like inserting records, editing, deleting) similiary to how I modify data in a GradView using a DataList or repeater? I want to be able to have my own EditTemplate and be able to edit say four fields while I'm only viewing like two of them in the datalist/repeater. <asp:DataList ID="DataList1" runat="server" DataKeyField="GameId" DataSourceID="SqlDataSource1" RepeatColumns="1"> <ItemTemplate> <%# Eval("field1") %><%# Eval("field2") %>.... </ItemTemplate> <EditTemplate>......</EditTemplate>
When I'm trying to add a edit-button (<asp:Button runat="Server" ID="EditButton" Text="Edit" CommandName="Edit" />) and click it nothing happens....What is missing?
Here is tested schemaif exists (select * from dbo.sysobjects where id =object_id(N'[dbo].[TestTable]') and OBJECTPROPERTY(id, N'IsUserTable')= 1)drop table [dbo].[TestTable]GOCREATE TABLE [dbo].[TestTable] ([SerialNumber] [char] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,[test1] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[test2] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[test3] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,[test4] [char] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NULL) ON [PRIMARY]GOinsert into testtable values ('123','pass',null,'fail','skip')insert into testtable values ('456','fail',null,'pass','skip')insert into testtable values ('789',null,'fail','skip','pass')insert into testtable values ('345','pass','pass','pass','fail')I would like to fetch the COLUMNNAME where the value is fail.Basically I need to know which test failed, test1, test2, test3 ortest4?Is this possible?
i am using a view grid to display data the viewgrid is tied to an sqldatasource control i want to give the user the ability of modifing data by colomn instead of by row how could i do ?
is there a way to do this in create/alter table without the overhead of a trigger? I want to ensure that one of the 'key' values (even though it may be duplicated) cannot change after it's been inserted.
In MySQL it's simple to insert new columns in specific locations in a table like this
sql Code:
Original - sql Code
alter table foo add column bar integer not null default 0 after baz
ALTER TABLE foo ADD COLUMN bar integer NOT NULL DEFAULT 0 AFTER baz
But attempting to do the same thing in MSSQL fails with a syntax error on the word "after." I can insert columns in MSSQL but only if they are added to the end. I looked at the Microsoft insert documentation here but don't see any way to replicate the above MySQL command.
Is there any way to do this in MSSQL? Or do I have to completely recreate all my tables from scratch?
I want to write SQL that will search the tables in a database for a specific column, like this. For instance, I have a column "Unique_ID" that is in many of our tables (hundreds) but not in others and want to find out the tables it is in. It is always the first column.
I tried to find a system stored procdure to do this but couldn't and tried to create a script using the sysobjects and syscolumns tables in the Master db, but came to a roadblock because they don't seem to be related at all.
I would surely appreciate if someone else has already done this!
I have an existing VB6 application which uses an Access 2003 backend datafile, however, I would now like to modify this to use an SQL 2005 datafile, but I don't know how to go about this or the implications when the application is installed on another machine.
The code I use for accessing the Access 2003 file is below, I want to convert this code to access an SQL 2005 datafile instead, can anyone give me some pointers on the best way to go about this, or code sample.
Dim rst As ADODB.Recordset Dim dbs As ADODB.Connection
Set rst = New ADODB.Recordset Set dbs = New ADODB.Connection