Avatar billede cbadk Novice
17. august 2007 - 22:25 Der er 8 kommentarer og
1 løsning

MSSQL Nchar problem

Når man bruger Nchar i MSsql udskriver den alle 50 char, selvom kun de 10 feks er brugt.

Nogle der har et forslag?

Eksempel:
<meta name="keywords" content="minside.dk admin desc                              " />

/cbadk
Avatar billede morhan Novice
17. august 2007 - 22:32 #1
Avatar billede kalp Novice
18. august 2007 - 02:25 #2
kald Trim() på din string.. og ellers først ToString().Trim()
Avatar billede a1a1 Novice
18. august 2007 - 11:27 #3
du kunne også lave feltet om til en nvarchar ;o)

char (og nchar) bør kun bruges hvis dine felters indhold har samme længde...(eller tæt på)

;o)
Avatar billede cbadk Novice
20. august 2007 - 11:48 #4
Ugler i mosen. Det er noget værre noget at skrifte fra mysql til mssql :D

Men tak for jeres svar. Nu har jeg kun det sidste problem...det bliver og få dato formatet til og passe ind i mssql :)
Avatar billede a1a1 Novice
20. august 2007 - 12:28 #5
tjaaa....

CONVERT(<yourdate>, 10, 113)
eller
CAST(<yourdate> AS SMALLDATETIME)
Avatar billede a1a1 Novice
20. august 2007 - 12:32 #6
(fra mssql help)
Syntax for CAST:
CAST ( expression AS data_type [ (length ) ])

Syntax for CONVERT:
CONVERT ( data_type [ ( length ) ] , expression [ , style ] )
Avatar billede a1a1 Novice
20. august 2007 - 12:35 #7
SQL Server supports the date format in Arabic style by using the Kuwaiti algorithm.

In the following table, the two columns on the left represent the style values for converting datetime or smalldatetime data to character data. Add 100 to a style value to obtain a four-place year that includes the century (yyyy).

Without century (yy) (1)  With century (yyyy)  Standard  Input/Output (3) 
-
0 or 100 (1, 2)
Default
mon dd yyyy hh:miAM (or PM)

1
101
U.S.
mm/dd/yyyy

2
102
ANSI
yy.mm.dd

3
103
British/French
dd/mm/yy

4
104
German
dd.mm.yy

5
105
Italian
dd-mm-yy

6
106 (1)
-
dd mon yy

7
107 (1)
-
Mon dd, yy

8
108
-
hh:mm:ss

-
9 or 109 (1, 2)
Default + milliseconds
mon dd yyyy hh:mi:ss:mmmAM (or PM)

10
110
USA
mm-dd-yy

11
111
JAPAN
yy/mm/dd

12
112
ISO
yymmdd

-
13 or 113 (1, 2)
Europe default + milliseconds
dd mon yyyy hh:mm:ss:mmm(24h)

14
114
-
hh:mi:ss:mmm(24h)

-
20 or 120 (2)
ODBC canonical
yyyy-mm-dd hh:mi:ss(24h)

-
21 or 121 (2)
ODBC canonical (with milliseconds)
yyyy-mm-dd hh:mi:ss.mmm(24h)

-
126 (4)
ISO8601
yyyy-mm-ddThh:mm:ss.mmm (no spaces)

127(6)
ISO8601 with time zone Z.
yyyy-mm-ddThh:mm:ss.mmmZ

(no spaces)

-
130 (1, 2)
Hijri (5)
dd mon yyyy hh:mi:ss:mmmAM

-
131 (2)
Hijri (5)
dd/mm/yy hh:mi:ss:mmmAM


1  These style values return nondeterministic results. Includes all (yy) (without century) styles and a subset of (yyyy) (with century) styles.

2. The default values (style 0 or 100, 9 or 109, 13 or 113, 20 or 120, and 21 or 121) always return the century (yyyy).

3  Input when you convert to datetime; output when you convert to character data.

4  Designed for XML use. For conversion from datetime or smalldatetime to character data, the output format is as described in the previous table. For conversion from float, money, or smallmoney to character data, the output is equivalent to the style value of 2. For conversion from real to character data, the output is equivalent to the style value of 1.

5. Hijri is a calendar system with several variations. SQL Server 2005 uses the Kuwaiti algorithm.

Important: 
By default, SQL Server interprets two-digit years based on a cutoff year of 2049. That is, the two-digit year 49 is interpreted as 2049 and the two-digit year 50 is interpreted as 1950. Many client applications, such as those based on Automation objects, use a cutoff year of 2030. SQL Server provides the two digit year cutoff configuration option that changes the cutoff year used by SQL Server and allows for the consistent treatment of dates. We recommend specifying four-digit years.



6. Only supported when casting from character data to datetime or smalldatetime. The time zone indicator, Z, is optional. Character data representing only date or only time components will be cast to the datetime data type. The unspecified time component is set to 00:00:00.000, and the unspecified date component is set to 1900-01-01.

When you convert to character data from smalldatetime, the styles that include seconds or milliseconds show zeros in these positions. You can truncate unwanted date parts when you convert from datetime or smalldatetime values by using an appropriate char or varchar data type length.

;o)
Avatar billede cbadk Novice
20. august 2007 - 12:57 #8
Klip og Klister :D

Mange tak...
Avatar billede a1a1 Novice
20. august 2007 - 13:13 #9
ja, det er altid godt ;o)
tak for points...
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester