Friday, November 8, 2019

SQL Server - Set Default Time stamp in date

set default time, add time in date, default timestamp, time stamp

Another story :)
some time we need to add timestamp along with the date, or we need to replace existing timestamp with custom timestamp
Yes this is doable and it is very easy.

Here i am going to show a example from AdventuresWorks database, object will be user person.person and fieldname is createdDate.

1. I am converting first datetime to date only
2. Append date with default timestamp

This will work on both either on date field or on datetime field

select cast(createddate as date) ,DATEADD(day, DATEDIFF(day, 0, cast(createddate as date) ), '11:00:00.000') from [Person].[Person]

How to execute SQL query on CMD using text file and log result in text file

SQLcmd is small and easy to use tool is us with from last few decades. For starters SQL CMD is good and for some developers they are use to on cmd screen. They love to do query upon the screen, all is about the taste of doing work.

SQLCMD is command line can be used with in the cmd itself. You can execute the sql some Tsqls and any type of query using script. So this article is about the same that how to execute sql from script file using a sqlcmd.

At the same time we can generate the output of the script which is being executed in sqlcmd using "-o" parameter.

SQL script can be call using "-i" parameter.

sqlcmd -S IP_ADDRESS -d Database_Name -U Username -P Password -i C:\Users\***\Desktop\test.sql -o C:\Users\***\Desktop\test1.log
web stats