sql-server-2008

sql server 2008: setting up a username properly in order to connect from VBA

i set up a login (reviewer) under security for SQL SERVER and under the specific database i set up a User (qcvalues_reviewer) that references this login i have tried all these different ways to login into the database from vba: 'cn.Open "Provider=SQLOLEDB;Data Source=hermes;Initial Catalog=test;User ID=qcvalues_reviewer; Password=921...

Help on creating Fiscal Year 12 Periods

Hi, I am developing a financial application using SQLServer 2008 as database and I want to generate fiscal periods of any year for example Input : June 2010 Results desired 12 periods from the starting date of June 2010 - May -2011 Period…………….Start…………………………....………..End 1…...………………1-06-2010……………………………30-06-2010 2..........1-07-2010...

How do I declare and assign a variable on a single line in SQL

Easy points. Quick search didn't tell me what I wanted. I want something like DECLARE myVariable nvarchar[MAX] = "hello world". Bonus points if you show me how to encode a quote in the string. eg. I want the string to read John said to Emily "Hey there Emily" my attempt would be DECLARE myVariable nvarchar[MAX] = "John said to ...

Generate MD5 hash string with T-SQL

Is there a way to generate MD5 Hash string of type varchar(32) without using fn_varbintohexstr SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes('MD5', '[email protected]')), 3, 32) So it could be used inside a view with SCHEMABINDING ...

CSV import in SQL Server 2008

I have a csv file that has column values enclosed within double quotes. I want to import a csv file from a network path using an sql statement. I tried bulk insert. But it imports along with double quotes. Is there any other way to import a csv file into SQL Server 2008 using an sql statement by ignoring the text qualifier double quot...

How to re-seed a table identity in SQL Server 2008 and undo it all safely?

I need to do this for testing only, but then undo it when the test is done. I have seen some tutorials online on how to re-seed a table, but not so much on how to undo it. Let's say the table definition is the following: create table beer ( beer_id numeric(10) not null, mnemonic nvarchar(8) ); go Let's say that I want the ...

SQL - Best way to GroupByDay from 6AM to 6AM

I need to query a large number of rows (containing a timestamp column) and aggregate the results by day. The trick is I need the aggregate functions to be grouped for each day from 6AM until next day at 6AM, not from midnight to midnight. Obviously, I can do some sort of "group by DATEPART(day,Timestamp-6 hours)" but for millions of row...

sql server: how do i get the last record that was inserted?

i am doing this: With rs .AddNew ' create a new record ' add values to each field in the record .Fields("datapath") = dpath .Fields("analysistime") = atime .Fields("reporttime") = rtime .Fields("lastcalib") = lcalib .Fields("analystname") = aname .Fields("reportname") = rname .Fields("batchstate") = b...

GUID: varchar(36) versus uniqueidentifier

I'm working with a legacy database that stores GUID values as a varchar(36) data type: CREATE TABLE T_Rows ( RowID VARCHAR(36) NOT NULL PRIMARY KEY, RowValue INT NOT NULL ) INSERT T_Rows (RowID, RowValue) VALUES (NEWID(), 1) I would assume that storing a GUID as a uniqueidentifier would be preferable since it's o...

SQL Server Management Studio 2008: save database diagrams without applying tables just yet

Can you create a database diagram for a database and save it without creating the actual tables? You know, so the boss can check it out before you apply it? ...

Creating Batch update in Classic ASP and ADO

I have an ASP form that brings in a number of records that I want to modify and then update. Currently, the updates take place as one-at-a-time update through DLL's that simply build a SQL statement and call the database for each record. Now, I need to place a check in the SQL to make sure that I'm not getting rid of the last type of l...

T-SQL Dynamic xquery

Hi All, I am trying to figure out how I can load my table variable with data from XML using dynamic xquery? I am getting a result set of nodes from the query and defining the value type of those nodes. It seems that it is the value definition of the nodes that it is blowing up on. Here is an example of the script that works, but is ...

Read only access to stored procedure contents

Is it possible to set up SQL Server to give developers read-only access to the contents of stored procedures on our production database? ...

TSQL Openquery with Text Field hangs up MS SqlServer

This happens when I query a text field using linked server. For example: select * from openquery(LS,'select text_field from table') then my server blows up! HELP? ...

app.config file in C# for SQL Server 2005 in VS 2008

I have C# .net project with SQL Server 2008 written in Visual Studio 2008. There I used the following connection string to connect with SQL Server: string connectionString = @"server=HASIBPC\SQLEXPRESS; Integrated Security=SSPI; database=XPHotelManagementDatabase"; But problem is every time I take my application from one c...

SSIS Package run from SQL Server Agent Job no longer do Logging

I Have a package stored in SQL Server which works properly with logging when I run it directly by right-clicking it in SQL Server, with logging. Logging is set to 'SSIS log provider for Text File'. When I run it from an SQL Server Agent Job, it works fine, without errors but the logging isn't done. The job runs with the my user, the s...

SQL Query for adding missing values for a field between two dates?

Ok, So I have these two tables - BioUser- UserId,Weight,DateAdded DimDate-Date // It has basically all the dates for any period..its basically a table with all dates till 2050 Now the BioUser table has entries for weight of a user but not for everyday but whenever they enter their weight. So I want to basically build a list of values...

How to find duplicate records in SQL?

I am trying to develop a query to insert unique records but am receiving the SQL Server Primary Key error for trying to insert duplicate records. I was able to insert some values with this query but not for this record (score_14). So now I am trying to find duplicate record with the following query. The challenge is that my PK is ba...

Composite primary key with foreign key relationships to multiple tables. SQL Server 2008 Errors

USE [Fk_Test2] GO /****** Object: Table [dbo].[Owners] Script Date: 08/20/2010 16:52:44 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO SET ANSI_PADDING ON GO CREATE TABLE [dbo].[Owners]( [Owner] [varchar](10) NOT NULL, CONSTRAINT [PK_Owners] PRIMARY KEY CLUSTERED ( [Owner] ASC )WITH (PAD_INDEX = OFF, STATIST...

Violation of Primary Key constraint error

I am using SSMS 2008 and trying to insert with this query but am getting the following error: Msg 2627, Level 14, State 1, Line 1 Violation of PRIMARY KEY constraint 'PK_j5c_MasterMeasures'. Cannot insert duplicate key in object 'dbo.j5c_MasterMeasures'. The statement has been terminated. Here is my query: insert into J5C_MasterMeasu...