|
USE tempdb ;
GO
DECLARE @ladderTable TABLE ( Col1 INT ) ;
DECLARE @incrementValue INT = 0 ;
INSERT INTO @ladderTable ( Col1 )
VALUES ( 5 ),
( 10 ),
( 15 ),
( 20 ) ;
SELECT TOP 1
@incrementValue = Col1
FROM @ladderTable
ORDER BY Col1 ASC ;
SELECT st.Col1,
CAST(st.Col1 AS VARCHAR(20)) + '-'
+ CAST(ISNULL(dt.Col1, st.Col1 + @incrementValue) - 1 AS VARCHAR(20)) AS LadderSequence
FROM @ladderTable AS st
LEFT OUTER JOIN @ladderTable AS dt ON st.Col1 < dt.Col1
AND ( st.Col1 + @incrementValue ) >= dt.Col1 ;
GO
Thanks,
Karunakar
|
|
|
|
|
I need to give an introductory database course to a bunch of people who generally are able to write simple SQL queries, but still mainly use files to save stuff. (fits files, ascii files, csv files, ...)
My course starts with presenting some pro's and con's, explaining the basic structure (tables, links, constrains, keys, indexes, ...) and diving into some basic SQL. A second lesson (still under development) would be coding against databases (creating a connection, SQL injection, ...)
I also included a lab with exercises (for lesson 1, lesson 2 to be done).
I looked at some tutorials on the internet, but still would like some advice on how to best bring this topic.
thanks in advance.
|
|
|
|
|
V. wrote: A second lesson (still under development) would be coding against databases (creating a connection, SQL injection, ...)
I'd recommend explaining sprocs and functions, moving to Xml in the third lesson. Creating a connection to the database from a non-sql language has little to do with SQL.
What's their role? If design comes into play, you could reserve a week for the topic of database-normalization. There's examples on structures that break normalization on the wikipedia[^]; the update-anomaly is always a nice intro as people recognize it from the real world
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Thanks! that already helps !
|
|
|
|
|
After reading several documents , i am still confused whether to use Filestream or Varbinary for storing files?
my application need PDf files to be saved in database , size can be between 100 KB to 4 MB
I guess in order to use filestream we have to configure server to use that. while varbinary can work as it is.
what will be best way?Experts please comment.
Thanks.
|
|
|
|
|
|
We use filestream only to reduce the size of the database backup which is retained for some ridiculous number of years! documents are backed up seperately.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
|
Hi Everyone,
I need a help in sql.
Below is the details:
from the front end, i will select few sql objects
for eg,
i am selecting
a) ProcedureName1, View_1 from Company_BAT and
b) GetEmpByProjID,GetAllProj, samplefunction from Company_DEV
here
ProcedureName1,GetEmpByProjID,GetAllProj are procedures.
View_1 is a view.
samplefunction is a function.
ProcedureName1 uses a) View_1 (View_1 uses Table_1)
b) Table_1
c) Table_2
View_1 uses a) Table_1
GetEmpByProjID uses a) Employee
GetAllProj uses a) Employee
b) Project
samplefunction a) it doesnt uses any objects
i need the output in the format as in the below screenshot in the below link:
http:
PLease advise, how to obtain result in this format.
|
|
|
|
|
hi,i have a problem!!!
How can I get the Sqllocaldb of database backup????
thankyou
|
|
|
|
|
|
Thanks for the reply .but I do not want backup in managment studio.
I want the backup (sqllocaldb) to do the coding in Visual 2012.
is It possible??/
|
|
|
|
|
i want to show report based on date condition and show it in gridview. It is working in my local machine but not working in server after hosting.
query is SELECT * FROM table WHERE DATE(colmn1) between 'startdate' and 'enddate'
What could be the problem.
If anybody knows please reply me.
Thanks in advance
|
|
|
|
|
ven753 wrote: What could be the problem.
It could be the format of the date. Why is there a DATE-function on colmn1? Is it a varchar?
Please don't crosspost. The question should not be in the .NET forum.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
i work in a broadcasting company i just need a suggestion to build a database for the company .The workflow is the data form nas,ftp,airbox, which will go in the database to validate the data and then it flow towards workstation is it possible ?
|
|
|
|
|
aman wangde wrote: The workflow is the data form nas,ftp,airbox
Look up what a workflow is.
aman wangde wrote: then it flow towards workstation is it possible ?
Nas and FTP, sure, you can write applications to synchronize them with a database. What's an Airbox?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
I just used the Import Export functionality in sql 2008 to export a table having about one million rows. I have exported to a flat file, and delimited with pipes.
For some reason, about 23,000 rows below, the one of the fields expands and as a result pulls down to the next row, creating a blank row, the data hence after is fine. Now and then we are getting these blank rows.
I have confirmed this data is of length 40 characters long or less.
What could be causing the odd line breaks in the flat file?
any ideas appreciated!!
Thanks!
|
|
|
|
|
Is there a carriage-return or line break embedded in the field?
If you can isolate one of the affected rows, try dumping the characters from the affected field:
DECLARE @FieldValue varchar(100);
SELECT @FieldValue = AffectedField FROM AffectedTable WHERE Key = @AffectedKey;
WITH E1(N) AS
(
SELECT 1
UNION ALL SELECT 1
UNION ALL SELECT 1
UNION ALL SELECT 1
UNION ALL SELECT 1
UNION ALL SELECT 1
UNION ALL SELECT 1
UNION ALL SELECT 1
UNION ALL SELECT 1
UNION ALL SELECT 1
),
cteNumbers (N) As
(
SELECT
ROW_NUMBER() OVER (ORDER BY (SELECT NULL))
FROM
E1 a, E1 b
)
SELECT TOP(LEN(@FieldValue))
N,
Ascii(Substring(@FieldValue, N, 1)) As AsciiCode,
Substring(@FieldValue, N, 1) As Character
FROM
cteNumbers
ORDER BY
N
;
You're looking for either a 10 or a 13 in the AsciiCode column.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Hi,
What is wrong with this syntax?
I have used this so many times in sql 2005. Kind of new to sql 2008.
===
bcp "Select * From Webs.About" queryout mytest.dat -T -c
===
the error message is
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'queryout'.
|
|
|
|
|
Not sure if this is it, but try enclosing mytest.dat in quotation marks. Otherwise, it looks like it should work to me.
-NP
Never underestimate the creativity of the end-user.
|
|
|
|
|
Also, make sure you are running the bcp utility from the command prompt. I think if you try running it from a new query window within SMS that is exactly the error you will get. I'm pretty sure the quotation marks I mentioned in my previous post won't help unless the file name has a space in it.
-NP
Never underestimate the creativity of the end-user.
|
|
|
|
|
How can I ran this through a new query window in SQL?
Using xp_cmdshell?
Thanks!!
|
|
|
|
|
Sure, you can use xp_cmdshell to run a bcp command from a query window. You might have to first turn on the ability for SSMS to use a Windows command shell as it is usually off by default. If needed, run the following commands first:
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
EXEC sp_configure 'xp_cmdshell', 1
RECONFIGURE
Then run your xp_cmdshell using: EXEC xp_cmdshell '(your bcp command here)'
If needed, turn back off the ability to use Windows command shell with:
EXEC sp_configure 'xp_cmdshell', 0
RECONFIGURE
EXEC sp_configure 'show advanced options', 0
RECONFIGURE
-NP
Never underestimate the creativity of the end-user.
|
|
|
|
|
Hi all,
I have posted the same question some time ago... but I didn't get any solution. Please read below first...
I want to connect a MySql Database.
Suppose.....
Database Name is mydb
Database located on PC-1 (IP- 192.168.0.10)
PC-1 user id = abc
PC-1 password= 123
MySQL Server user ID = root
MySQL Server password= mypassword
now what will be the connection string for PC-1 to connect to the database ?
now I want to connect the database(mydb) from another pc (suppose this pc name is PC-2 and the IP is 192.168.0.11)
what will be the connection string for PC-2 to connect the PC-1 database ?
I searched connectionstrings.com[^] and found ...
Standard
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
and
Specifying TCP port
Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;
Pwd=myPassword;
but nowhere found if the server pc (PC-1) is protected by user id and password. In this case what should I do ?
I Tried both the above connection string. They are Ok for PC-1 to connect its own database (localhost) but when I tried to connect the database from PC-2, I got the error
Quote: Host '192.168.0.11' is not allowed to
connect to this server
<big>Can anybody help me ?</big>
|
|
|
|
|
Biplob Singha Shee wrote: Can anybody help me ? Reposting your question isn't going to help.
Biplob Singha Shee wrote: Please read the entire question first I did. Twice. The answer "I cannot do that" doesn't mean that the answer you have been given was incorrect. You could have asked how to find the path. I'd answer that you can search your entire HD. By hand.
Most (professional) databases do not allow making remote connections in a default install. It's a security-thing. You cannot change that using a connection-string.
The fact that you're using XAMP simply means that the config-files are in another location than the default MySQL path. You'd have to find the file yourself, make the change to allow remote connections, and restart the server.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|