sql-server-2008-r2

How to eliminate NULL fields in TSQL

人走茶凉 提交于 2019-12-20 07:38:25
问题 I am developing a TSQL query for SQL Server 2008 R2. I am trying to develop this query to identify one record / client. Because some of these values are NULL, I am currently doing LEFT JOINS on most of the tables. But the problem with the LEFT JOINs is that now I get > 1 record for some clients. But if I change this to INNER JOINs then some clients are excluded entirely because they have NULL values for these columns. How do I limit the query result to just one record / client regardless of

Column is invalid in select

馋奶兔 提交于 2019-12-20 07:17:13
问题 How I will properly do this: Customer CusID, CusLname, CusFname, CusMname, CusAddress, CusEmailAdd Order OrderID, Order, CusID SQL Select Count(OrderID), o.CusID, CusLname, CusFname, CusMname, CusAddress, CusEmailAdd From Customer c Inner join Order o On c.CusID = o.CusID Group By o.CusID Error Column 'CusLname, CusFname, CusMname, CusAddress, CusEmailAdd' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. Why do I need to add

How to insert data of a CSV file into SQL Server db table using powershell

試著忘記壹切 提交于 2019-12-20 06:35:05
问题 I want to do this by executing PS Script from my local machine.. where DB server is remote machine. And in the CSV file I don't have any column names specified.(only comma separated and aligned o/p). I don't want to use BULK INSERT 回答1: There are two ways I would approach this: BCP.exe SQL Server provides the command line utility bcp to bulk import data. You could simply incorporate the bcp execution into your Powershell script or window to load the csv data. Example: $loadfile = "C:\datafile

vb.net using ashx handler to get image from SQL Server

不打扰是莪最后的温柔 提交于 2019-12-20 06:29:16
问题 I have employee images stored in my EMPPhotos table on SQL Server 2008 R2 in an image datatype. I created a generic handler to get the image from the table and send it to the page. It does not work. I have tested the query itself and I am getting data. The handler: <%@ WebHandler Language="VB" Class="EmpImageHandler" %> Imports System Imports System.Web Imports System.Drawing Imports System.Drawing.Imaging Imports System.IO Imports System.Data Imports System.Data.SqlClient Public Class

SQL Server : Encrypt / Protect stored procedure

穿精又带淫゛_ 提交于 2019-12-20 05:56:09
问题 I am just wondering any good tools or software that you can recommend me to protect / encrypt my stored procedure that was developed on SQL Server 2008 R2 ? I read about create stored procedure with encryption and is it possible to get it decrypted in case I have bugs in the program? Also, came across CLR but I don't think I want to create a stored procedure in Visual Studio environment. Or I could be wrong. Hope you can give me some advise while I am still researching on this topic. Final

SqlDependency.OnChange not firing in WinForm?

倾然丶 夕夏残阳落幕 提交于 2019-12-20 05:12:21
问题 I used Detecting Changes with SqlDependency as example for the code that I'm writing. I've also looked at other links with similar code, but none of them work. Essentially, I simply want to change label1.Text when a change has been made to table [ErrorLog] . For some reason, OnDependencyChange is not firing. I've enabled Service Broker in the database: ALTER DATABASE TestDB SET ENABLE_BROKER WITH ROLLBACK IMMEDIATE Now, here's my complete code. It's very short: public partial class Form1 :

What is Best Approach for Opening/Closing SqlConnection in C#

。_饼干妹妹 提交于 2019-12-20 04:19:48
问题 I would like to know what could be best approach to open a SqlConnection with Sql Server 2008R2 Express Edition Database. This Version of Sql has Limitations of RAM Usage and CPU Usage so we must adopt something best to open a SqlConnection . Right Now i am Checking Connection on Start and End of each and every Method. Here is an example of that. private void CheckValidId(string Id) { CheckConnectionStatus(); try { sqlConnection.Open(); sqlCommand = new SqlCommand("select * from ValidId where

TSQLT unit test - The data types text and text are incompatible in the equal to operator

前提是你 提交于 2019-12-20 04:14:09
问题 I am getting this error from AssertEqualsTable "The data types text and text are incompatible in the equal to operator." then "The 'TableCompare' procedure attempted to return a status of NULL, which is not allowed. A status of 0 will be returned instead." select * into #Actual from [dbo].[InvoiceOut]; --make expected table an empty table of #actual's structure because we truncate so it should be empty. SELECT TOP(0) * INTO #Expected FROM #Actual; EXEC tSQLt.AssertEqualsTable '#Expected', '

SQL add processed ids to a single cell seperated with a comma

隐身守侯 提交于 2019-12-20 04:13:33
问题 i have the following sql query to get an idea of what it does please read the description below select catalogid, numitems, allitems - numitems ignoreditems from ( select i.catalogid, sum(case when (ocardtype in ('PayPal','Sofort') OR ocardtype in ('mastercard','visa') and odate is not null) AND NOT EXISTS ( select * from booked b where b.ignoredoid = o.orderid ) then numitems else 0 end) numitems, sum(numitems) allitems from orders o join oitems i on i.orderid=o.orderid group by i.catalogid

SQL Query for aggregation/concatenation

谁说胖子不能爱 提交于 2019-12-20 03:48:26
问题 I have a table like this: ID Name ---------- 1 john 1 molly 2 greg 2 sean 1 holly 2 mill What should the SQL Query be to aggregate results like the following: ID Name ------------- 1 john/molly/holly 2 greg/sean/mill 回答1: Note: The STUFF function simply removes the leading / from the string returned. SELECT t1.id, STUFF((SELECT '/' + t2.name FROM YourTable t2 WHERE t1.id = t2.id ORDER BY t2.name FOR XML PATH('')),1,1,'') AS Name FROM YourTable t1 GROUP BY t1.id 来源: https://stackoverflow.com