sql-server

Is this the correct way to use sp_executesql in a stored procedure?

I have this huge stored procedure where I am building a sql statement. At the end, I create a parameter list like this: DOES @paramList need and N in front of it?? SELECT @paramList = '@param1 nvarchar(300), @param2 nvarchar(10), @param3 nvarchar(10), @param4 nvarchar(100), @param5 nvarchar(1000), @param6...

SQL Server Boolean Expression evaluation

I have a table that stores data from the county appraisal district. I want to add a computed column to tell me if the property is owner-occupied. I define "owner occupied" as true if the property address is the same as the owner address, false otherwise. Because of data entry inaccuracies in the source data from the county, if I do a st...

Examples of SQL injection even when using SQLParameter in .NET?

I heard that SQL Injection can still be possible when using ADO.NET SQLParameter (paramterised query) for SQL Server. I am looking for real examples in C#/VB code as proof. EDIT: I am looking for SPECIFIC working examples. Not introductions to sql injection or how to prevent it. ...

Performance monitoring sql server and not logging onto the server

A book I was reading, on sql server 2008, mentions how you should not directly logon to the db server to do performance monitoring etc. This begs the question, what is the best way to do this task without going on the server? Run jobs? Through some sort of command prompts? Thanks ...

Can I modify a value in setting.setting file?

I am working on a Windows form application with C#,and it would be really helpful if I could modify a value in "setting.setting" file in the program properties. In fact I want to put connection string for SQL database in this file and get it when needed so I need to change it if the connection changed. ...

Error in query with XML data type

Hi, I have a query that strips data from a XML string, inserts it into a table variable and queries it to insert the data into another table. It runs like a charm in my localhost environment, but not in my production SQL Server database. The error message is "INSERT failed because the following SET options have incorrect settings: 'ARITH...

How to drop SQL default constraint without knowing its name?

In Microsoft SQL Server, I know the query to check if a default constraint exists for a column and drop a default constraint is: IF EXISTS(SELECT * FROM sysconstraints WHERE id=OBJECT_ID('SomeTable') AND COL_NAME(id,colid)='ColName' AND OBJECTPROPERTY(constid, 'IsDefaultCnst')=1) ALTER TABLE SomeTable DROP CONSTRAINT DF_SomeTa...

Having trouble with this simple SQL Select statement.

I have two tables, A and B. Both have the exact same columns. I need to select all the items in TableA that ARE NOT in TableB. This is intersection, right? How can I do this? ...

SQL Selecting rows that are in both tables.

How can I select rows that exist is two tables. The intersection I guess? Any help? ProductosA and ProductosB, they're both tables with the exact same number and type of columns. How can I select the things that are inside of both using a single select statement? ...

SQL Injection, simplest solution.

I'm unsure how someone would break my SQL if I simply replace all incoming single quotes with double quotes. Can someone enlighten me for both Oracle and SQL Server examples? Thanks. string sql1 = "select * from users where user_id = '" + "O'Reily".Replace("'", "''").Replace("\", "") + "'"; ==> "select * from users where user_id = 'O...

Determine if a row for an fk exists in any one of 20 tables

I was trying to determine a better way than so many IF/THEN statements to determine if ONE OR MORE tables contain a ref to a forign key. I simply need to know (true/false) if a row exists in any one of 20 tables. All tables have the same fk field. I hope this makes sense, if not i'll try to explain further. ...

How does Microsoft certification 70-432 help in career building re: SQL Server and who should go for it?

How does Microsoft certification 70-432 help in career building re: SQL Server and who should go for it? ...

sql query to test my programming capabilities in diffrent way

i have one table and one column in this.there is 15 data(integer).i want to count positive numbers and negative numbers and also sum of total numbers in one query . can any one help me ......... ...

datename method in sqlserver

how to show the day (like : sunday,monday ...) in sql query i write like this select datename(day,getdate()) but it give numaric values but i want sunday,monday,tuesday..... please give some soulution ...

SQL Select subquery

I'm a little new to SQL and have come across the following problem. I have a table with company details on it which is joined to a contact table by an enqID. Within the contact table, there are 4 different types of contacts which may or may not have an entry. These are differentiated by a ctcTypID (1 - 4) I would like to produce a qu...

Select latest revision of each row in a table

I have table structures that include a composite primary key of id & revision where both are integers. I need a query that will return the latest revision of each row. If I understood this answer correctly then the following would have worked on an Oracle DB. SELECT Id, Title FROM ( SELECT Id, Revision, MAX(Revision) OVER (PARTITION BY...

SQL Server CLR Stored Procedure JSON Parameter

Hello, I've come across a scenario where I want to pass a large amount of data to a Stored Procedure for generating some dynamic SQL. The data I want to pass is stored in this Json/C# class object that I use in my ASP.NET MVC web project. [ { "code":"ABC123", "Count": "12998", "Params": [ {"name": "Recent", "value": "0-12...

Parent-Child Relationship: E-R Diagram

Would you please let me know a reference document or web references for a good E-R diagram displaying Parent Child relationships between the tables (Min. of 8 tables) with MS SQL Server 2008 database? I am planning to design a big database, so looking forward for your help. ...

Table Valued Function where did my query plan go?

I've just wrapped a complex SQL Statement in a Table-valued function on SQLServer 2000. When looking at the Query Plan for a SELECT * FROM dbo.NewFunc it just gives me a Table Scan of the table I have created. I'm guessing that this is because table is created in tempdb and I am just selecting from it. So the query is simply : SEL...

Trying to connect to MDF Database without using a trusted connection

Hi, Is there anyway to connect to an MDF file without using a trusted logon? I've gone into management studio and created an account called bob with password bob, given that account full access and also added the account to the database. When i try to connect using that account I get the following error Login in failed for user 'bob'....