sql-server-2008-r2

Column is invalid in select

纵饮孤独 提交于 2019-12-02 10:36:28
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 those columns in the Group By Clause? What will I do to select those columns without having them in the

extended events blocked process report missing from sys.dm_xe_objects

北战南征 提交于 2019-12-02 10:30:14
Trying to create SERVER EVENT SESSION to capture blocked_process_report & xml_deadlock_report events to a file for later analysis with the following statement; CREATE EVENT SESSION [blocked_process] ON SERVER ADD EVENT sqlserver.blocked_process_report( ACTION(sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.database_name)) , ADD EVENT sqlserver.xml_deadlock_report ( ACTION(sqlserver.client_app_name, sqlserver.client_hostname, sqlserver.database_name)) ADD TARGET package0.asynchronous_file_target (SET filename = N'c:\temp\XEventSessions\blocked_process.xel', metadatafile = N'c:

Check if SQL object is referenced by any other SQL objects

拟墨画扇 提交于 2019-12-02 10:02:20
I was just reading this SO thread and had a question for @Mack regarding whether there is a way to check if a SQL object is referenced by any other SQL objects. He (@Mack) used T-SQL and DMVs to accomplish something similar in his answer. Is this possible, if so how? I would have posted this as a comment, but I don't have sufficient reputation yet... You can, but not with a DMV instead you'll need a related dynamic management function (DMF) dm_sql_referencing_entities (more info here ). Here is the code: SELECT referencing_schema_name , referencing_entity_name FROM sys.dm_sql_referencing

Display SQL time field on Access form as Access medium time hh:mm am/pm

爷,独闯天下 提交于 2019-12-02 09:58:27
问题 I am using Access 2010 linked to SQL Server 2008 R2. My problem - how do I display time on an Access form as hh:mm am/pm instead of SQL Server's time(7) format of hh:mm:ss.nnnnnnn ? To complicate things, I do have a look-up table with all the times in half hour time frames? Ex. in SQL, the lookup field says 07:30:00.0000000 - I want to choose a time from the dropdown in my Access form that says 7:30 am and then display it on the Access form as 7:30 am. If I choose it, I want it to store in

SQL Server : Encrypt / Protect stored procedure

爷,独闯天下 提交于 2019-12-02 08:39:12
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 objective would be, I don't want people to view my stored procedure and steal it for own use. Thanks. It

how to pass default value to date parametere in storedprocedure - Sqlserver 2008?

半城伤御伤魂 提交于 2019-12-02 08:26:16
Here it is my stored procedure: ALTER proc [dbo].[allrecp] @peid int=0, @pename varchar(20)='', @pdes varchar(20)='', @pdoj date='1111-1-1', @sal money=0, @dept int=0, @loc int=0,@i int=0 as begin if(@i=1) begin insert into Employee values(@pename,@pdes,@pdoj,@sal,@dept,@loc) end if(@i=2) begin update Employee set ENAME=@pename,DESEGNATION=@pdes,DOJ=@pdoj,SALARY=@sal,DEPTID=@dept,LOCATIONID=@loc WHERE EMPID=@peid end if(@i=3) delete EMPLOYEE where EMPID=@peid end And my c# code is: private void btndelete_Click(object sender, EventArgs e) { parameteres(3); } private void btnupdate_Click(object

Best way to extract segments / values from VARCHAR field in SET based SQL

江枫思渺然 提交于 2019-12-02 08:19:10
Take the following example data: SELECT 'HelpDesk Call Reference F0012345, Call Update, 40111' AS [Subject] UNION ALL SELECT 'HelpDesk Call Reference F0012346, Call Resolved, 40112' AS [Subject] UNION ALL SELECT 'HelpDesk Call Reference F0012347, New call logged, 40113' AS [Subject] What i would like to do is extract this data as follows: As you can see, i need to extract the Ref, Type & OurRef as seperate columns to ensure efficient set based SQL when processing the resulting emails. Usually for this scenario i would use a function such as this: CREATE FUNCTION dbo.fnParseString ( @Section

Control on XML elements nesting using FOR XML

倖福魔咒の 提交于 2019-12-02 08:08:40
I state my problem by example. In fact i foudna solution after trying in many ways but i would like to ask whether this solution is good or if for any reason it is better to use an alternative approach. In fact i need to control how elements are created. i first made a view containing all the data i needed and then i selected from teh view by joining the view more times. I reproduced the "complexity" here using a local variable instead of a view: DECLARE @Employees table( EmpID int NOT NULL, Name nvarchar(50), Surname nvarchar(50), DateOfBirth date, DepartmentID int, AccessLevel int); insert

Writing data to text file using BCP prompts for file storage type

帅比萌擦擦* 提交于 2019-12-02 07:58:35
I'm copying data from SQL to text file using bcp tool with following command: bcp.exe "exec <StoredProcedure>" queryout "temp.txt" -T -r\n -c This command runs as expected on test environment and creates/updates required file without additional prompts. But when it's run in client's environment, bcp additionally prompts for field length, prefix and field terminator- so when command is run from SQL Agent job, it get's stuck in infinite wait. Any ideas why is this happening? Based on bcp documentation , when -c parameter is used - it shouldn't prompt for type, etc. and should use char as the

SQL Service Broker - communication scenario - migration from SQL 2008 R2 to SQL 2014

大憨熊 提交于 2019-12-02 07:44:44
问题 Summary: Is there anything new in SQL Server 2014 (versus 2008 R2) that does not allow the following scenario? Can the same approach be transfered to the new server? The application uses SQL Service Broker to collect data from satellite SQL Express machines (technology computers, now two, soon 4, and possibly more) to the central SQL Server with SQL Server Standard edition. It is based on simplified security settings without the need to exchange certificates. I was asked to migrate the