sql-server

getting problem in group by clause

hi friends, i want to get the sum of quantity from the below query. how i write the group by clause in below mention query. select top 1 EvrId, TimeStamp, Date, BnhTnkMik1 as Quantity, (select TnkCode from Tanklar where TnkId=BnhTnkId) as Tank, FuelCode, InvoiceNo from Evrak join Hareket on (BnhEvrId=EvrId) join Stoklar on (StokId=Bn...

How to remove accents and all chars <> a..z in sql-server?

I need to do the following modifications to a varchar(20) field: substitute accents with normal letters (like è to e) after (1) remove all the chars not in a..z for example 'aèàç=.32s df' must become 'aeacsdf' are there special stored functions to achieve this easily? UPDATE: please provide a T-SQL not CLR solution. This is ...

TRY CATCH in SQL Server

I am using SQL Server 2008. I have tried to execute the following: BEGIN TRY SELECT 1/0; END TRY BEGIN CATCH PRINT 'ERROR' END CATCH; But I am getting the following error: >Msg 170, Level 15, State 1, Line 1 Line 1: Incorrect syntax near 'TRY'. Msg 156, Level 15, State 1, Line 3 Incorrect syntax near the keyword 'END'. Can ...

SQL Server Max statement returns multiple results

When querying two tables (t1, t2) and using a MAX statement for a column in t2, SQL returns multiple entries. This seems to be because I also query other info from t2 which consists of unique entries. Simplified table example t1.number t2.number_id t2.sync_id t2.text 1 1 1 ...

Turn off implicit transactions

Hello everyone, I would like to do a insert into using a select, but I know that some rows might fail (that is expected). Is there a way to change the implicit transactions of SQL Server 2008 off so that the ones that have not failed are not rolled back? -- get the count of the customers to send the sms to SELECT @count = COUNT(*) FROM ...

Delete All / Bulk Insert

First off let me say I am running on SQL Server 2005 so I don't have access to MERGE. I have a table with ~150k rows that I am updating daily from a text file. As rows fall out of the text file I need to delete them from the database and if they change or are new I need to update/insert accordingly. After some testing I've found that ...

TSQL Function to calculate 30 WORKING days Date from a Specified Date (SQL Server 2005)

TSQL Function to calculate 30 WORKING days Date from a Specified Date (SQL Server 2005)? Input parameters would be Date and Number of Working Days. Output would be the Calculated Date. This would exclude Saturday, Sunday, Holidays and Day Holiday was observered. i.e. If the Holiday falls on a weekend but it is observed on the Friday ...

How do you find a missing number in a table field starting from a parameter and incrementing sequentially?

Let's say I have an sql server table: NumberTaken CompanyName 2                      Fred 3                      Fred 4                      Fred 6                      Fred 7                      Fred 8                      Fred 11                    Fred I need an efficient way to pass in a parameter [StartingNumber] an...

Transform a parent/child table to a fixed column dimentional table

I've a relational table (id, parentId, name) which I'd like to convert to a flattened dimentional table (id, Level1, Level2, Level3, Level4) I'm ok fixing the depth at 4 deep. I've made progress with a recursive CTE and pivot, but the result set isn't right I get Id Name Level1 Level2 0 Root NULL NULL 1 NULL L1 NUL...

How to set a permission to let a SQL server user to access for certain tables

I just created two tables and they are named as tblA and tblB. I also created a user(Security/Login) who will be used for a remote insert/update. What is the best way to permit this user to access for only those two table out of 50 table. I have tried look for the way from (Security/Login) and (Database/Properties). Can I limit it fro...

How to connect to a DB on windows

I have a SQL server 2005 server database on a server and need to conect to it from a client on the same server network, any ideas? ...

optimize stored procedure

Hi All, I have one question on how to optimized my sp, actually it was a view but I decided to change to sp to make it faster, and it did work. First it took 27 seconds for a view to run and 16 sec for sp. So it is getting better but how to make it even better? Table that I am running my sp on is 600 records and I am returning around 80...

provider cannot be found error in python connecting to SQL Server

I'm attempting to connect to a SQL Server database within a Python script. I'm using SQLNCLI as provider on my connection string. from win32com.client import Dispatch connection_string = "Provider=SQLNCLI;server=%s;initial catalog=%s;user id=%s;password=%s"%(server,db_name,user,pwd) dbConn = Dispatch("ADODB.Connection") dbConn.Open( ...

Cursors vs. While loop - SQLServer

Say I have a bunch of rows in a DB (SQLServer 2008 in this case) that can be used to create equations. ----------------------------------------------------- OperationID | EquationID | Operation | Amount | Order ----------------------------------------------------- 1 | 1 | + | 12 | 1 2 | ...

Select records with a substring from another table

Hi, I have this two tables: data id |email _ 1 |[email protected] 2 |[email protected] 3 |zzzgimail.com errors _ error |correct @gmial.com|@gmail.com gimail.com|@gmail.com How can I select from data all the records with an email error? Thanks. ...

Loop on all database query in sql server

I have multi dbs with same structure I want to loop on them to check this select statment select scan1,scan2,scan3 from customers where .............. the output would be database name if this select has records like that: db1 db2 db3 and so on ... ...

Remote connect to SQL Server Express 2008 is unreachable

Hello, I have a SQL Server Express 2008 on a machine, this could be XP, 7, 32/64bit. I have configured the SQL for TCP/IP, NamedPipes etc...opened my router to forward the 1433 port from external to 1433 into my SQL Machine. A tool from forward.com seems to see my port correctly open. I drop my firewall just to make sure. But again no ...

SQL Server 2008: copying the contents of all tables from one database into another database

I have two databases with THE SAME schema. I need to copy the contents of all the tables from one database into the other database. What is the best way to do this>? There are about 200 tables. I have ssms. ...

Return SQL Query as Array in Powershell

I have a SQL 2008 Ent server with the databases "DBOne", "DBTwo", "DBThree" on the server DEVSQLSRV. Here is my Powershell script: $DBNameList = (Invoke-SQLCmd -query "select Name from sysdatabases" -Server DEVSQLSRV) This produces my desired list of database names as: Name ----- DBOne DBTwo DBThree I has been my assumption that a...

SSIS XMLSource only seeing null values in XML variable

I have a Data Flow task with an XMLSource that references an XML Variable. The DataFlow task does recognize that there are x number of rows in the variable, but it only sees null values in every row: The xml variable value: <?xml version="1.0" encoding="utf-8"?> <words> <word>butter</word> <word>crispy</word> </words> I used th...