I Tabelle Stadt mit diesem Schema genannt haben:Unicode in StoredProcedure Parameter
CREATE TABLE [dbo].[City](
[Id] [bigint] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](50) NOT NULL,
[CreatedDate] [datetime] NOT NULL,
[CreatedBy] [nvarchar](256) NULL,
[UpdatedDate] [datetime] NOT NULL,
[UpdatedBy] [nvarchar](256) NULL,
[SoftDelete] [bit] NOT NULL,
[LanguageKey] [nvarchar](2) NOT NULL DEFAULT (''),
[ProvinceName] [nvarchar](50) NULL DEFAULT (''),
[CityImageId] [bigint] NULL,
[CityDescription] [nvarchar](500) NOT NULL DEFAULT (''),
[CityLinkTo] [nvarchar](100) NOT NULL DEFAULT (''),
[CityCode] [nvarchar](100) NOT NULL DEFAULT (''),
CONSTRAINT [PK_dbo.City] PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[City] WITH CHECK ADD CONSTRAINT [FK_dbo.City_dbo.Image_CityImageId] FOREIGN KEY([CityImageId])
REFERENCES [dbo].[Image] ([Id])
GO
ALTER TABLE [dbo].[City] CHECK CONSTRAINT [FK_dbo.City_dbo.Image_CityImageId]
GO
Und es ist mit diesem Code eine gespeicherte Prozedur:
in der Stadt TabelleALTER Proc [dbo].[InventoryReport]
(
@startDate datetime ,
@endDate datetime ,
@cityName nvarchar(50)
)
AS
Begin
Select Id , Name , AllPlace , InventoryPlace , case when Percentage is null then Convert(nvarchar(5),0) else Convert(nvarchar(5) ,Percentage)End AS Percentage
From (
Select c.id , c.Name Name, count(p.id) AllPlace , count(inventoryPlace.InventoryId) InventoryPlace ,
ROUND(Convert(float , NULLIF(count(inventoryPlace.InventoryId), 0) )/ Convert(float,NULLIF(count(p.id), 0) ),2,null) Percentage
from Place p
left join (
Select id InventoryId , name from (
Select ROW_NUMBER() Over(Partition by id , name Order by id , date) rn,
* from (
Select
p.id , p.name , i.date
from Place p
left join Room r on p.id = r.placeid and p.SoftDelete = 0 and r.SoftDelete = 0
join RoomService rs on r.id = rs.roomid and rs.SoftDelete = 0
join inventory i on rs.id = i.roomServiceId and i.SoftDelete = 0
AND i.date >= @startDate and i.date <@endDate and Price <>0
Group By p.id , p.name , i.Date
)a
)r
where r.rn = DATEDIFF(day , @startDate , @endDate)
)inventoryPlace
on p.Id = inventoryPlace.InventoryId
right join City c
on c.id = p.CityId and c.SoftDelete = 0
Where
(@cityName is null OR @cityName = N'' OR c.Name = @cityName) and p.SoftDelete = 0 and IsVisible = 1
Group By c.id , c.name
) As PlaceInventoryReport
Order by Id
END
das Feld Name ist Nvarchar(50)
und @cityName
ist nvarchar(50)
entweder. Ich ausführen diese unter Codes:
exec InventoryReport @startDate='2016-07-22 00:00:00',@endDate='2016-08-21 00:00:00',@cityName =N'بیرجند'
exec InventoryReport @startDate='2016-07-22 00:00:00',@endDate='2016-08-21 00:00:00',@cityName ='بیرجند'
die erste von SQL Profiler erzeugen execute und aus der Anwendung aufrufen, dann ergibt sich nichts (das ist falsch) und der zweite Anruf praktisch von selbst und führt einen Datensatz. der unterschied ist N'
die beiden werte 'بیرجند' sind die gleichen in charakter und ich habe sie von ort kopiert. Ich kann nicht erkennen, was falsch ist und warum führen diese beiden Anweisungen anders aus?
Vielen Dank im Voraus.
N-Präfix teilt SQL Server die Zeichenfolge als Unicode-value.whereas zu behandeln, wenn don'y die gleiche erwähnen es als string..more Info zu sehen sein wird, hier: https://support.microsoft .com/de-de/kb/239530 – Malcolm
@Malcolm Wenn wir den Datentyp der Spalte zu NVARCHAR definieren, speichern Sie den Wert im UNICODE-Format oder nur eine Zeichenfolge? Wenn es als String speichert, warum sollten wir nicht Varchar von 8000 Char Length verwenden? Wenn es im UICODE-Format speichert, warum stimmt der Wert nicht überein? –
@samira Haben Sie in der Spalte genaue Sortierung für die Sprache verwendet? –