I'm using SQL Server Management Studio to manage my database.
The problem is that if I have a nchar(50) column in a table and I insert a value of test, what I will find in my table is this value
test<46spaces>
These spaces are making so much trouble for me. How can I stop this strange action?
Thank you
The reason is you're using char / nchar which are fixed length strings. Change your datatype to nvarchar.
Related
I have a few BigInt measures in an SSAS cube which I would like to have comma separated by thousands. But despite trying various formatting options I haven't been successful.
In the measures' properties, first I set the datatype to BigInt and set the FormatString and Format options to #,##0;-#,##0. The front-end application didn't show them comma separated (I'm using Kyubit Analysis Portal).
Then I changed the datatype to int; The values were now comma separated, but I got negative numbers due to overflows (the numbers for those measures are all positive).
I then tried to change the datatype to UnsignedInt and faced the initial issue (the values were not comma separated).
Then I tried the Currency data-type and I almost got the results I wanted: values were comma separated by thousands but now I had two 0 decimals that I didn't need (e.g. ###,###,###.00)
So my question is: How do you format BigInt values in SSAS to have them comma separated by thousands on the front-end application?
I'm using SQL Server 2012.
This seems to be a SQL Server 2012 bug. I used some SQL Server 2008 front end tools to browse the cube (including SQL Server Management Studio 2008) and the issue was resolved. I ended up using #,##0 as FormatString option.
I have a table containing a nvarchar column [AffectedNodes] that looks something like this when you take a peek at its contents (two variations shown):
"MID128; MID129; MID130"
"[1,3,2]; [3,1,2]"
We are working on a change which will move the AffectedNodes into its own table [AffectedNode] that has a nvarchar column [NodeId], which should store one of the nodes from the above string. I'm tasked with migrating the existing content to the new format.
As you can see the values are split using semi-column and a space.
To follow the database upgrade process they use in our project I have to write an SQL query in SQL Server CE. I'm wondering how I could do this in a neat way. Thanks!
SQL CE supports, CHARINDEX and SUBSTRING function, did you check that out or did you see any issue with them?
I have a SQL Server database that contains a VarChar(50) column. I am using ASP.NET/C# for this application.
I have protected my program from SQL injection so when I insert any text with an apostrophe in it, it will insert properly. I have confirmed this in the database.
However, now when I query the database for this varchar column, instead of getting apostrophes in the column, I am getting the unicode version of it (' ;).
I use a SqlDataSource and bind it to a DataGridView. What could cause this conversion? How can I avoid it?
EDIT:
Seems that this problem is only occurs in textboxes, labels seem to be displaying them properly.
Thanks for your help. This community here is awesome!
To fix data in the database: Replace the ascii apostrophe with a real apostrophe in a sql database
And how to correctly insert:
How to insert a value that contains an apostrophe (single quote)?
-- Edit --
This thread seems to shed more light on this issue: http://forums.asp.net/p/1554455/3818604.aspx
You could also try the HtmlDecode(string) method via http://msdn.microsoft.com/en-us/library/system.web.httpserverutility.htmldecode.aspx
How can I insert Arabic characters into a SQL Server database? I tried to insert Arabic data into a table and the Arabic characters in the insert script were inserted as '??????' in the table.
I tried to directly paste the data into the table through SQL Server Management Studio and the Arabic characters was successfully and accurately inserted.
I looked around for resolutions for this problems and some threads suggested changing the datatype to nvarchar instead of varchar. I tried this as well but without any luck.
How can we insert Arabic characters into SQL Server database?
For the field to be able to store unicode characters, you have to use the type nvarchar (or other similar like ntext, nchar).
To insert the unicode characters in the database you have to send the text as unicode by using a parameter type like nvarchar / SqlDbType.NVarChar.
(For completeness: if you are creating SQL dynamically (against common advice), you put an N before a string literal to make it unicode. For example: insert into table (name) values (N'Pavan').)
Guess the solation is first turn on the field to ntext then write N with the value. For example
insert into eng(Name) values(N'حسن')
If you are trying to load data directly into the database like me, I found a great way to do so by creating a table using Excel and then export as CSV. Then I used the database browser SQLite to import the data correctly into the SQL database. You can then adjust the table properties if needed. Hope this would help.
So I have a stored procedure in a SQLServer 2005 database, which retrieves data from a table, format the data as a string and put it into a varchar(max) output variable.
However, I notice that although len(s) reports the string to be > 8,000, the actual string I receive (via SQLServer output window) is always truncated to < 8,000 bytes.
Does anybody know what the causes of this might be ? Many thanks.
The output window itself is truncating your data, most likely. The variable itself holds the data but the window is showing only the first X characters.
If you were to read that output variable from, for instance, a .NET application, you'd see the full value.
Are you talking about in SQL Server Management Studio? If so, there are some options to control how many characters are returned (I only have 2008 in front of me, but the settings are in Tools|Options|Query Results|SQL Server|Results to Grid|Maximum Characters Retrieved and Results to Text|Maximum number of characters displayed in each column.
The data is all there, but management studio isn't displaying all of the data.
In cases like this, I've used MS Access to link to the table and read the data. It's sad that you have to use Access to view the data instead of Management Studio or Query Analyzer, but that seems to be the case.
However, I notice that although len(s) reports the string to be > 8,000
I have fallen for the SQL Studio issue too :) but isn't the maximum length of varchar 8,000 bytes, or 4,000 for nvarchar (unicode).
Any chance the column data type is actually text or ntext and you're converting to varchar?