sql-server-2008

Insert converted varchar into datetime sql

帅比萌擦擦* 提交于 2021-02-20 19:53:51
问题 I need to insert a varchar in my table. The type in the table is a datetime so I need to convert it. I didn't think this would be to big of a problem however it keeps inserting 1900-01-01 00:00:00.000 instead of the date I want. When I do a select with my converted date it does show me the correct date. I'll show you the code: INSERT INTO Item (CategoryId, [Date], Content, CreatedOn) SELECT CategoryId, Convert(datetime, '28/11/2012', 103), Content, GetDate() FROM Item i JOIN Category c ON i

Insert converted varchar into datetime sql

大憨熊 提交于 2021-02-20 19:51:09
问题 I need to insert a varchar in my table. The type in the table is a datetime so I need to convert it. I didn't think this would be to big of a problem however it keeps inserting 1900-01-01 00:00:00.000 instead of the date I want. When I do a select with my converted date it does show me the correct date. I'll show you the code: INSERT INTO Item (CategoryId, [Date], Content, CreatedOn) SELECT CategoryId, Convert(datetime, '28/11/2012', 103), Content, GetDate() FROM Item i JOIN Category c ON i

Types don't match for creating a CLR Stored Procedure

丶灬走出姿态 提交于 2021-02-20 07:02:58
问题 I have a method in an assembly that looks like this: namespace MyNameSpace { public class MyClass { [Microsoft.SqlServer.Server.SqlProcedure] public static void MyMethod(SqlChars myMessage) { // Stuff here } } } I compile that to a dll and load it into my SQL Server like this: drop assembly MyAssembly create assembly MyAssemblyfrom 'C:\Scripts\MyAssembly.dll' That all works fine. But now I try to run this: CREATE PROCEDURE MySproc @message nvarchar(max) AS EXTERNAL NAME MyAssembly.

SQL BCP with column name

天涯浪子 提交于 2021-02-20 04:44:07
问题 I am trying to export my stored procedure to a .csv file using BCP. It does give me a output file in .CSV but it does not print column name. Below is the script. Please look at and let me know what i am missing DECLARE @command VARCHAR(4000) declare @fulldate varchar(30) = convert(varchar,GETDATE(),112) declare @year varchar(30) = left(@fulldate,4) declare @day varchar(30) = right(@fulldate,2) declare @month varchar(30) = left(right(@fulldate,4),2) DECLARE @FileDirectory VARCHAR(1000) = 'c:\'

System.AccessViolationException in .NET 4.0 while connecting to SQL Database

此生再无相见时 提交于 2021-02-20 04:08:43
问题 I have created following code Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("default").ConnectionString Dim con As New SqlConnection(ConnectionString) con.Open() Response.Write("Connection Opened<br/>") con.Close() Response.Write("Connection Closed<br/>") in a web application project Target .NET Framework 4.0 but it is giving System.AccessViolationException i cannot understand why. if i change the target Framework to .NET 3.0 then the code runs fine. Below is the

System.AccessViolationException in .NET 4.0 while connecting to SQL Database

落花浮王杯 提交于 2021-02-20 04:07:30
问题 I have created following code Dim ConnectionString As String = ConfigurationManager.ConnectionStrings("default").ConnectionString Dim con As New SqlConnection(ConnectionString) con.Open() Response.Write("Connection Opened<br/>") con.Close() Response.Write("Connection Closed<br/>") in a web application project Target .NET Framework 4.0 but it is giving System.AccessViolationException i cannot understand why. if i change the target Framework to .NET 3.0 then the code runs fine. Below is the

Filter Power BI report based on current user

北城余情 提交于 2021-02-19 05:39:12
问题 We're currently developing a Power BI Dashboard (Office 365) for our company and would like to tailor the information on the dashboard based on the current user's preferences. Our company has multiple departments and sub-departments, so to display every department's figures to all users would be counter-productive. For example if Bob is in Sales for Europe - he'll only see European sales, while Sue will only see Sales for America. Is there a way PowerBI can identify the current user and then

Using SqlDependency with named Queues

别说谁变了你拦得住时间么 提交于 2021-02-18 10:41:13
问题 I have the following code that uses SqlDependency to monitor changes in one of my databases It works great, except every run it generates its own Queue/Service/Route with a guid in the database: Class: class SqlWatcher { private string connectionString; private string sqlQueue; private string listenerQuery; private SqlDependency dependency; public SqlWatcher(string connectionString, string sqlQueue, string listenerQuery) { this.connectionString = connectionString; this.sqlQueue = sqlQueue;

Using SqlDependency with named Queues

我只是一个虾纸丫 提交于 2021-02-18 10:41:10
问题 I have the following code that uses SqlDependency to monitor changes in one of my databases It works great, except every run it generates its own Queue/Service/Route with a guid in the database: Class: class SqlWatcher { private string connectionString; private string sqlQueue; private string listenerQuery; private SqlDependency dependency; public SqlWatcher(string connectionString, string sqlQueue, string listenerQuery) { this.connectionString = connectionString; this.sqlQueue = sqlQueue;

Sql Server union with If condition

♀尐吖头ヾ 提交于 2021-02-18 09:33:52
问题 I have a query like: DECLARE @tmpValue SET @tmpValue = 0 -- it will be change SELECT * FROM Animal WHERE AniActive = 1 UNION IF @tmpValue > 0 SELECT * FROM Animal WHERE.Active = 0 When I use like this it is giving error because of if condition. I have to use UNION because of our structure. How can I use it with if condition? Thanks, John 回答1: Move the condition @tmpValue > 0 to the WHERE clause like so: SELECT * FROM Animal WHERE AniActive = 1 UNION SELECT * FROM Animal WHERE @tmpValue > 0