Hi all,
is there a function in SQLServer 2005 that returns NULL if any of the arguments (of any type) is NULL, which would saves me from writing IF a IS NULL OR b IS NULL OR c IS NULL ....
Hi,
I have two tables, one table has rowguid column and other has auto incremented column but both tables dont have primary key or foreign key. I want to create third table that store the relationship between above two tables. can somebody give me the correct and easiest way to do that. i m new using sqlserver. please reply me
declare @fieldForceCounter as int
declare @SaleDate as dateTime
declare @RandomNoSeed as decimal
set @fieldForceCounter = 1
set @SaleDate = '1 Jan 2009'
set @RandomNoSeed = 0.0
WHILE @fieldForceCounter <= 3
BEGIN
while @SaleDate <= '1 Dec 2009'
begin
INSERT INTO MonthlySales(FFCode, SaleDate, SaleValue) VALUES(@fieldForceCounter, @SaleDate, RAND(@RandomNoSeed))
set @saleDate = @saleDate + 1
set @RandomNoSeed = Rand(@RandomNoSeed) + 1
end
set @SaleDate = '1 Jan 2009'
set @fieldForceCounter = @fieldForceCounter + 1
END
GO
This T-SQL command was supposed to insert random values in the 'SaleValue'-column in the 'MonthlySales'-table.
But it is inserting '1' every time .
What can be the problem?
I am looking to learn more about full text indexing and I am looking for more information than is available in SQL Books online or at least something that presents full text indexing in a different way. Does anyone have any recommendations on books.
Hi
I have a table as shown below.
ID ParentID Node Name Node Type
------------------------------------------------------------------
525 524 Root Area Level 1
526 525 C Area Level 2
527 525 A Area Level 2
528 525 D Area Level 2
671 525 E Area Level 2
660 527 B Area Level 3
672 671 F Area Level 3
How can i write a recursive t-sql query to generate below output?
Output ("Root" node not required in the output):
Node ID
-----------------------
A 527
A/B 660
C 526
D 528
E 671
E/F 672
Thanks
Alright so I want to convert an already exist MSSQL database (2005) to a MYSQL database.
There is nothing extraordinary to be done
The only things I need to achieve is
Recreate the tables
Transfer data
Relationships would be nice but not necessary
No views, no sprocs, no functions.
Any easy way to do this.
Also do you know of any DST (Database Synchronization Tool)
which would let me do
MSSQL to MYSQL
MYSQL to MYSQL
MSSQL to MSSQL (I know there is SQL Delta for this)
I can't find anything like that. Commercial or free ( XSQL Lite is suitable for my case and ) tools show diffs in grids with possibility to export to CSV. Also they generate sync SQL scripts when run from command line. What I need is an output as a comprehensive report ( XML , HTML ) suitable for parsing so that I would be able to show similar diff grid in my application ( updated old/new values for each column , added - all values for row , deleted - all values for row and etc... ) .
I am using SQLServer 2008 & 2005 (Express). I'm trying to extract part of an alpha numeric string from a varchar field.
RIGHT(str_field,3) yields null values but substring(str_field, len(str_field)-2, len(str_field)) gives the right value. left(str_field,7) gives the expected values. What gives? I would have thought that RIGHT(str_field,3) and substring(str_field, len(str_field)-2, len(str_field)) are equivalent expressions.
I'm curious. Is there any way to prevent SQL query execution plans from being cached for an entire connection's duration?
Can I run a command that basically says, "use OPTION(RECOMPILE) for all subsequent commands until I tell you to stop doing so?"
I'm acutely aware of all the performance trade-offs here, and I know this is not a step to be taken lightly. However, I'm in a unique situation where this behavior may be advantageous.
I am trying to see a list of tables from Adventureworks DB from "Person" schema in SqlServer 2008. I developed teh following SP, but after running it as follows it gives me error "Incorrect syntax near ')'". Do you know how I can revise this SP or exec statement?
CREATE PROCEDURE [getTableNames]
@SchemaName VARCHAR(50)
AS
BEGIN
SET NOCOUNT ON;
SET @SchemaName = 'PERSON'
DECLARE @cmd AS VARCHAR(max)
SET @SchemaName = RTRIM(@SchemaName)
SET @cmd = N'SELECT TABLE_NAME ' +
'FROM information_schema.Tables ' +
'WHERE TABLE_TYPE = ''BASE TABLE'' AND TABLE_SCHEMA = @SchemaName'
END
exec sp_executesql getTableNames, N'@SchemaName NVARCHAR(50), @SchemaName'
Hey smarties. I'm having trouble with the following SQL statement. I know that I can't do a GROUP BY on the OnlineStatus column, and it makes sense because it's a function call, not an actual column in my table. How would I modify this so that I can get a count of how many users are online?
SELECT CASE dbo.fnGetWebUserOnlineStatus(W.Id)
WHEN 1 THEN 'Online'
WHEN 2 THEN 'Ingame'
ELSE 'Offline'
END AS OnlineStatus
FROM dbo.WebUsers W
WHERE W.[Status]=1
GROUP BY OnlineStatus
Hi I have following data in the table:
ID-----startDate----endDate
5549 2008-05-01 4712-12-31
5567 2008-04-17 2008-04-30 1
5567 2008-05-01 2008-07-31 1
5567 2008-09-01 4712-12-31 2
5569 2008-05-01 2008-08-31
5569 2008-09-01 4712-12-31
5589 2008-04-18 2008-04-30
5589 2008-05-01 4712-12-31
5667 2008-05-01 4712-12-31
5828 2008-06-03 4712-12-31
5867 2008-06-03 4712-12-31
6167 2008-11-01 4712-12-31
6207 2008-07-01 4712-12-31
6228 2008-07-01 4712-12-31
6267 2008-07-14 4712-12-31
I am looking for I way to group the continuous time intervals for each id to return:
ID,
min(startDate),
max(endDate),
to have something like this in result for the bolded ID 5567
5567 2008-04-17 2008-07-31
5567 2008-09-01 4712-12-31
PL/SQL is also an option here :)
Thanks,
I have a SQL Mobile database with one table. It has several columns with useful, often queried data and one column that stores a relatively large string per record (1000+ characters) that is not queried often.
Imagine this fake schema, the "lifeStory" field is the large one.
table1
String firstName
String lastName
String address
String lifeStory
A representative query would be
SELECT firstName, lastName, address FROM table1 WHERE firstName = :p1
Does anyone know of any performance concerns leaving that large, infrequently queried column in this table?
I have a issue about creating databases in SQL 2005.
I want to be able to change the default logical filename for the mdf file. At the moment the log logical filename ends in _log by default. I want the data logical filename to automatically end with _data for consistency.
Is there a way i can set this?
Andrew
I would like to be able to see the Identity Specification (not as worried about seed/increment) and hate having to scroll around on the column properties panel.
Is it possible to add a column next to Allow Nulls in the table designer for Identity Specification? Specifically I am concerned with MS SQL Management Studio 2008.
Hi,
I want to select the records from a table which are updated or added in the last one month (table doesn’t have any datetime field and I can’t change the table structure).
Is it possible to write a sql query for that? how to fetch those records from table
regards,
kumar
hi, i m not able to modify table in SQLserver. i m new to databases.
use work
go
alter table employee
modify id varchar(20)
error message is-
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'modify'
here is an screenshot
thanks
I created a query that takes a database backup at certain specified location.
I want to use it as a stored procedure but this should act as a global stored procedure so that whenever this SP is called. Then database backup is taken.
It uses DB_Name() to take database backup of owner database.
Is it possible to create any such SP or Function.
I am using sqlserver 2005
My ASP.NET MVC web app has a weird issue. In VS debugging mode it works as expected, but when I publish it to dedicated web server (windows 2003, IIS6) a sql query returns previous data even though underlying data was already updated through the same connection. It looks like as if a query returns cached data. What might be the problem?
I want to write a query like this:
For a table that has these columns:
ColA ColB ColC, ColD
select first(ColA, ColB, ColC, ColD)
distinct(ColB, ColC)
from table
order by ColD
The query is supposed to order the table by ColD, then group the results by the combination of ColB and ColC (they may have different data types) and returns the first rows (with all the columns of the table) in the groups.
How is it possible in MS SQLServer 2005?
I need to write a sql statement to select all users ordered by lastname, firstname. This is the part I know how to do :) What I don't know how to do is to order by non-null values first. Right now I get this:
null, null
null, null
p1Last, p1First
p2Last, p2First
etc
I need to get:
p1Last, p1First
p2Last, p2First
null, null
null, null
Any thoughts?
I want to change element name with following statement:
SET @myDoc.modify('replace value of (/CustomerInfo)[1] with "Customer"')
from
<CustomerInfo>
<ID1</ID>
</CustomerInfo>
to
<Customer>
<ID1</ID>
</Customer>
But failed. So how can i change it just in sql ?
I have a query that selects some fields to display from a table
SELECT Field1, Field2, Field3, Field4 FROM table1
I want instead of returning :
To return:
How could I modify my SQL statement to return the second figure ?
Or at least how to change the gridview properties of .Net to do so (if this is possible) ?
In PHP, I know that mysql_real_escape in much safer than using addslashes.
However, I could not find an example of a situation where addslashes would let an SQL Injection happen.
Can anyone give some examples?
Thanks!
Hello
I have the following test-code:
CREATE TABLE #Foo (Foo int)
INSERT INTO #Foo SELECT 4
INSERT INTO #Foo SELECT NULL
INSERT INTO #Foo SELECT 2
INSERT INTO #Foo SELECT 5
INSERT INTO #Foo SELECT 1
SELECT * FROM #Foo
ORDER BY
CASE WHEN Foo IS NULL THEN Foo DESC ELSE Foo END
DROP TABLE #Foo
I'm trying to produce the following output:
1
2
3
4
5
NULL
"If null then put it last"
How is that done using Sql 2005
/M