Panchotiya Vipul
Panchotiya Vipul

Reputation: 1296

Different result in view and stored procedure

My table structure like this

enter image description here

I am create view for this table

SELECT Entered FROM dbo.tbPatientReport

In the table data like this

enter image description here

If i execute view from sql query then it will give output like

select Entered from view_abc

enter image description here

Desired Output

Desired Output

Upvotes: 1

Views: 97

Answers (2)

Ashwin Parmar
Ashwin Parmar

Reputation: 3045

You should format date as you want in result. e.g.

SELECT FORMAT( Entered,'MM/dd/yyyy hh:mm:ss tt','en-US') AS 'US'

FORMAT is one of the new built-in String Function introduced as a Part of Sql Server 2012. It returns the value formatted in the specified format using the optional culture parameter value. It is not an Sql Server native function instead it is .NET CLR dependent function.

SYNTAX: FORMAT ( value, format [, culture ] )

Edit Can you test this will be working.

SELECT CONVERT(VARCHAR(20), SYSDATETIME(), 22)

Format: MM/DD/YY HH:MI:SS AM
Output: 10/25/13 2:21:00 PM

Only problem is you cannot get FullYear.

Upvotes: 2

Adrian Sullivan
Adrian Sullivan

Reputation: 397

Your [Entered] column [Datetime] in your table structure does not allow nulls, it's not ticked.

What version of SQL Management Studio are you using? And are you selecting the data in a plain select query or are you choosing to View the data? In older versions "View" opens the edit window with your code on top.

While in the editing view the last row will always be NULL as it is expecting new data.

Upvotes: 0

Related Questions